[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: creating a node-set at run-time

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

> -----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:  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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.