I am interested in this too. In the chapter 11 of XSLT spec, nothing is mentioned about this.
It looks like the implementations for XSLT vary for different vendors. I tried it in the MS IE 6, it gives me error:"Variable or parameter 'juicerName' cannot be defined twice within the same template. " Then I tried in the Netscape 7.0, it takes the first value. The I tried to use Xalan, it takes the second value. I am expecting somebody can shed a light on it.
I reviewed the "11.5 Variables and Parameters within Templates" in XSLT spec, seems like the MS IE 6's implementation follows the spec: The following is from the spec: A binding shadows another binding if the binding occurs at a point where the other binding is visible, and the bindings have the same name. It is an error if a binding established by an xsl:variable or xsl aram element within a template shadows another binding established by an xsl:variable or xsl aram element also within the template. It is not an error if a binding established by an xsl:variable or xsl aram element in a template shadows another binding established by an xsl:variable or xsl aram top-level element. Thus, the following is an error: <xsl:template name="foo"> <xsl aram name="x" select="1"/> <xsl:variable name="x" select="2"/> </xsl:template> However, the following is allowed: <xsl aram name="x" select="1"/> <xsl:template name="foo"> <xsl:variable name="x" select="2"/> </xsl:template> NOTE: The nearest equivalent in Java to an xsl:variable element in a template is a final local variable declaration with an initializer. For example, <xsl:variable name="x" select="'value'"/> has similar semantics to final Object x = "value";
Joined: Apr 24, 2002
Thanks Tong Chen, I can see this implementation problem. I tried in IE 6 and it gave me same error. Thanks
Hi, Tong Chen, I'm a beginner on XML. Could you please tell me how to get the output using MS IE 6.0, given the xml and xsl source files? Since nothing in both files refers the other one. Is additional file needed to connect them? Thanks a lot in advance.
Joined: Apr 26, 2002
it's super easy: 1. create a folder on your c: drive (for example, c:\myxml) 2. under "myxml" folder, create an XML file "hello.xml": <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="hello.xsl"?> <greeting> Hello, World! </greeting> 3. under "myxml" folder, create an XSL file "hello.xsl": <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl utput method="html"/> <xsl:template match="/"> <xsl:apply-templates select="greeting"/> </xsl:template> <xsl:template match="greeting"> <html> <body> <h1> <xsl:value-of select="."/> </h1> </body> </html> </xsl:template> </xsl:stylesheet> 4. open your IE, in the address bar, type in: C:\myxml\hello.xml