RE: [xsl] creating a node-set at run-time

Subject: RE: [xsl] creating a node-set at run-time
From: "Michael Leditschke" <mike@xxxxxxxxxxx>
Date: Wed, 5 Feb 2003 16:44:02 +1100

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Ross Ken
> Sent: Wednesday, 5 February 2003 3:10 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] creating a node-set at run-time
> 
> 
> Untested but how about
> 
> <xsl:param name="var">
> 	<xsl:for-each select="list/item[@ref]">
> 		<xsl:copy-of select="document(@ref)/root[@attrib='attrib-val']"/>
> 	</xsl:for-each>
> </xsl:param>
> 
> Ken Ross
> Ph: +61 7 32359370
> Mob: +61 (0)419 772299
> Email: Ken.Ross@xxxxxxxxxxxxxx
> 

I see a couple of limitations with this

1. It assumes the root element of every input document uses the name "root" 
2. It does a deep copy (the whole tree) of each input document rather than 
   simply the contents of the ref attribute of the root element.

If these are issues for you, try

<xsl:variable name="var">
	<xsl:for-each select="list/item[@ref]">
		<xsl:value-of select="document(@ref)/*[@attrib='attrib-val']/@ref"/>
	</xsl:for-each>
</xsl:variable>

The string value of var will then be the concatenation of the values of
all the ref attributes. 

Note that under XSLT 1.0, the processing options for variables as defined above
(i.e. as a result tree fragment) are fairly limited. It can
be turned into a node-set using a processor specific extension function, but because
text nodes are aggregated, var will be a pretty simple tree consisting of a root node 
and a single text node.

If you want individual elements for each match for subsequent processing, try adding 
an element definition around each occurrence

e.g.

<xsl:variable name="var">
	<xsl:for-each select="list/item[@ref]">
		<match>
		<xsl:value-of select="document(@ref)/*[@attrib='attrib-val']/@ref"/>
		</match>
	</xsl:for-each>
</xsl:variable>

Then you can do something like (assuming you are in microsoft land)

<xsl:for-each select="msxsl:node-set($var)/match">
  ...
</xsl:for-each>

You'll also need to define the msxsl namespace on an element prior to the
above, typically the root element of the stylesheet, as 
xmlns:msxsl="urn:schemas-microsoft-com:xslt"

Regards
Michael




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread