RE: [xsl] Can I predict the build order of nodes?

Subject: RE: [xsl] Can I predict the build order of nodes?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 15 Feb 2010 08:58:49 -0000
> I have not tried fully your ideas but they look perfect 
> although since this application is purely Microsoft we 
> already know the order. We'll need to test and make sure it 
> works in both just in case things change as we would want our 
> XSLs independent of transformer.

I don't think it would even be safe to assume that one processor will give
you the same result consistently. Your code could easily stop working if you
make some apparently irrelevant change, like changing the names of your
> You recommended:
> <xsl:param name="stylemasterfile" select="/winelist/stylemasterfile"/>
> Which we agree with by the way. We would have no problem with 
> this but cannot figure out why the server implementation of 
> Microsoft XSLT tries to resolve the full path of the XML file 
> in the document() command -- 
> document($stylemasterfile)/styles. When we use the above 
> method to set the <param>. It tries to find "styles.xml" in 
> the default Web Server directory and not in a relative 
> directory to the XSL.
> This structure we used (below) does not and the server looks 
> for "styles.xml" relative to the XSL:
> <xsl:param name="stylemasterfile">
>       <xsl:value-of select="/winelist/stylemasterfile"/>
> </xsl:param>

When you copy the nodes to a temporary tree, it changes the base URI to that
of the stylesheet, which will give different results for the document
function. (The two constructs are not in fact 100% equivalent, which is why
an optimizer cannot easily get rid of the inefficient copy operation. They
are 99% equivalent, which is why some of us keep repeating the message that
the direct select="" option is the one to use in preference in the 99% of
cases where the effect is the same.)
> <xsl:param name="stylemasterfile"
> select="string(/winelist/stylemasterfile)"/>
> This works, the document() function in Microsoft's XSL 
> Transform to think it is relative and does not prepend with 
> the Web Server path.

Yes, that's a reasonable and portable way to ensure that document() resolves
against the base URI of the stylesheet rather than than of the source
document. If the first argument to document() is a string (rather than a
node) then it will resolve against the stylesheet base URI.


Michael Kay 

Current Thread