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

RE: node-set() confusion

Subject: RE: node-set() confusion
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 16 Oct 2004 23:38:54 +0100
xsl node set
xsl:for-each changes the context node, in this case to a node in the result
tree fragment. Path expressions starting with "/" always select nodes within
the tree containing the context node. If you want to select nodes in the
original source tree, create a global variable:

<xsl:variable name="root" select="/"/>

and then select relative to that, e.g. $root/root/foo/bar 

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Alexander Macdonald [mailto:lists@xxxxxxxxxx] 
> Sent: 16 October 2004 23:54
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  node-set() confusion
> 
> I originally posted this question in the xalan-j-users mailinglist 
> thinking it was a bug in Xalan but after getting the same result with 
> the saxon xslt processor I'm not too sure...
> 
> I'm having problems when using the exslt:node-set() function as well. 
> I'm not sure if it's related or if I've just missed something 
> basic but 
> I'll explain it anyway:
> 
> *** here is my xml document:
> 
> <root>
>      <foo>
>          <bar id="1"/>
>          <bar id="2"/>
>          <bar id="3"/>
>      </foo>
> </root>
> 
> 
> 
> 
> *** and here is my xslt script:
> 
> <xsl:stylesheet version="1.0"
>      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>      xmlns:exslt="http://exslt.org/common">
> 
>      <xsl:output method="html"/>
> 
>      <xsl:template match="/">
>          <xsl:message>correct: <xsl:for-each 
> select="/root/foo/bar">found! </xsl:for-each></xsl:message>
> 
>          <xsl:variable name="result-tree-fragment">
>              <xsl:for-each select="/root/foo/bar">
>                      <bar id="{@id}"/>
>              </xsl:for-each>
>          </xsl:variable>
> 
>          <xsl:for-each select="/root/foo">
>                  <xsl:message>still correct: <xsl:for-each 
> select="/root/foo/bar">found! </xsl:for-each></xsl:message>
>          </xsl:for-each>
> 
>          <xsl:for-each 
> select="exslt:node-set($result-tree-fragment)/bar">
>                  <xsl:message>broken: <xsl:for-each 
> select="/root/foo/bar">found!</xsl:for-each></xsl:message>
>          </xsl:for-each>
>      </xsl:template>
> 
> </xsl:stylesheet>
> 
> 
> 
> 
> when parsed by xalan the output looks like this:
> 
> file:/home/test.xsl; Line #10; Column #-1; correct: found! 
> found! found!
> file:/home/test.xsl; Line #19; Column #-1; still correct: 
> found! found! 
> found!
> file:/home/test.xsl; Line #23; Column #-1; broken:
> file:/home/test.xsl; Line #23; Column #-1; broken:
> file:/home/test.xsl; Line #23; Column #-1; broken:
> 
> 
> I expected it to look like this:
> 
> file:/home/test.xsl; Line #10; Column #-1; correct: found! 
> found! found!
> file:/home/test.xsl; Line #19; Column #-1; still correct: 
> found! found! 
> found!
> file:/home/test.xsl; Line #23; Column #-1; broken: found! 
> found! found!
> file:/home/test.xsl; Line #23; Column #-1; broken: found! 
> found! found!
> file:/home/test.xsl; Line #23; Column #-1; broken: found! 
> found! found!
> 
> 
> can anybody help?

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.