Re: problem self-referencing using document('') to reference parameters
Jonas Sicking <[email protected]> Fri, 20 Apr 2007 15:12:15 -0700
| Newsgroups | gmane.comp.mozilla.devel.layout.xslt |
|---|---|
| Message-ID | <[email protected]> |
When using document('') you're not actually referring to the stylesheet
itself. The document() function pulls in a new document from the network
from the specified url, when you use the url '' that happens to resolve
to the same url as the stylesheet. But the document will still be pulled
down from the network (or, more likely in this case, from the cache) so
naturally changes to parameters won't be reflected.
What IE does sounds very strange to me and seems wrong.
Why not simply refer to parameters using '$test'?
/ Jonas
[email protected] wrote:
> Ok, so I'm doing some crazy self-referential stuff from within an XSL
> stylesheet, it actually doesn't surprise me that I've broken the
> XSLProcessor object...... When you call "setParameter", the
> parameter seems to get set right; that is, any reference to the
> parameter will display the updated value correctly. However, if you
> make a reference to that same parameter from within the XSL document
> (using document('') ) you will get the default value and, as far as I
> can tell, you will be unable to self-reference any parameter and get
> the non-default value.
>
> <?xml version='1.0'?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:output method="html" version="4.0" encoding="iso-8859-1"
> indent="yes"/>
> <xsl:strip-space elements="*"/>
>
> <xsl:param name="test" select="'test1'"/>
> <!-- default value = 'test1' -->
>
> <xsl:template match="/">
>
> <xsl:value-of select="document('')//xsl:param[@name='test']/@select" /
> <!-- spit out whatever is in the select attribute of the param named
> 'test' within this document,
> ... will ALWAYS return 'test1' in gecko -->
>
> <xsl:value-of select="$test" />
> <!-- will return 'test1', unless set with setParameter (or by setting
> parameters any other way)
> then it will be whatever it was set to -->
>
> </xsl:template>
> </xsl:stylesheet>
>
> The thing that makes me incredibly sad about this is that I developed
> my code in IE (make it work in IE, gecko never fails -- that's my
> moto) and sure enough, I can get it to work in IE -- just not in
> gecko.
>
> Sooo in trying to get this to work, I removed the usage of the
> XSLTProcessor.setParameter function and went straight to the XML
> source of the XSL file and set the parameter there... e.g.
>
> function setParam( param, value ) {
> xsl.documentElement.selectSingleNode("//xsl:param[@name='"+param+"']/
> @select").nodeValue="'"+value+"'";
> } -- of course i needed to grab my handy prototyped selectSingleNode
> function to try that out
>
> So after trying this call:
> setParam( "test", "test2");
>
> the alert of the XML source prior to translation clearly shows:
> <xsl:param name="test" select="'test2'"/>
>
> BUT the: <xsl:value-of select="document('')//xsl:param/
> [@name='test']/@select" />
> inside the for loop STILL returned the default value of 'test1' !
>
> A bug? By design? Bug by pushing limits of the design? who knows...
> it's probably a bad idea to do self-referential stuff anyway.
>