Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 3rd, 2007, 01:15 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

An XSLT stylesheet is an XML document and you will get an XML parser error if you include an unescaped <. You can escape the character either by writing it as &lt; or by putting it in a CDATA section - the two approaches are 100% equivalent.

However, the error "Error: Expected ')'" is clearly from the Javascript parser rather than the XML parser.

Either way, the problem has nothing to do with XSLT.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 3rd, 2007, 04:30 PM
Authorized User
 
Join Date: Nov 2003
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to seanmayhew
Default

Not to be argumentative in any way shape or form and I understand your point ......I would like someone to prove to me that a for loop can be done in xslt OUTSIDE OF things like xalan. Simple xslt linked to in an xml doc and opened in IE. A simple javascript section in the head of an html doc cdata or not before apply-templates that contains a for loop.... the reason for this is I have some javascript specific to this element of my workflow that would get lost placing somewhere else.

 
Old February 6th, 2007, 04:26 PM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

Sean, here's your proof.

Let's assume you have both "bidon.xml" and "lines.xsl" in the same directory;

=========
bidon.xml (shockingly simple isn't it?)
=========
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="lines.xsl"?>
<bidon/>

=========
lines.xsl (not too scary either)
=========
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:template match="/">
        <html>
            <head>
                <title>XSLT Generated HTML</title>
                <script>
            var nbTimes = 10;
            function init(){
                for(var i = 0; i &lt; nbTimes; i++){
                    document.write('line ' + i);
                    document.write('&lt;br/>');
                }
            }
                </script>
            </head>
            <body onload="init()"></body>
        </html>
    </xsl:template>
</xsl:stylesheet>

===========
resulting HTML (if you do the actual transformation)
===========
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>XSLT Generated HTML</title><script>
            var nbTimes = 10;
            function init(){
                for(var i = 0; i < nbTimes; i++){
                    document.write('line ' + i);
                    document.write('<br/>');
                }
            }
                </script></head>
   <body onload="init()"></body>
</html>

If you save bidon.xml and lines.xsl in the same directory and open bidon.xml in IE, you'll see that the script worked perfectly.

Rushman has now left the building...


Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested For-Each Loop In XSLT dghosh XSLT 10 July 2nd, 2008 04:34 AM
XSLT Loop? kwilliams XSLT 1 June 16th, 2008 06:04 PM
xslt when loop problem check XSLT 1 April 18th, 2008 08:47 AM
FOR LOOP IN XSLT im_himanshu2004 XSLT 0 October 10th, 2007 02:27 PM
loop in xslt vazarshahy XSLT 6 June 7th, 2006 04:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.