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

RE: XSL node reference problem

Subject: RE: XSL node reference problem
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 21 May 2004 11:22:24 +0100
xsl node
> so i have some trouble for 4 days with this problematic :
> I have an XML file like that :
> <FILE>
>       <SCALAR>
>             <LABEL>toto</LABEL>
>             <VALUE>123</LABEL>
>       </SCALAR>
>       <SCALAR>
>             <LABEL>tata</LABEL>
>             <VALUE>456</LABEL>
>       </SCALAR>
>       <STRUCT>
>             ...
>       </STRUCT>
>       <SCALAR>
>             <LABEL>titi</LABEL>
>             <VALUE>789</LABEL>
>       </SCALAR>
> </FILE>
> 
> and i have done a XSL Template that permitt me to obtain the path of a
> specific SCALAR :
> <xsl:template name="chercheNode">
>   <xsl:param name="nom"/>
>   <xsl:value-of select="descendant::*[ (self::struct or 
> self::scalar) and
> label =$nom ]"/>
> </xsl:template>

XML is case sensitive. If you use upper case in the source document, you
must use upper case in the stylesheet.

Are you expecting to find one node or several? Because xsl:value-of (in XSLT
1.0) will always give you the contents of the first selected node.

> 
> And I call this one with this :
> 
> <xsl:variable name="tata">
>   <xsl:call-template name="chercheNode">
>      <xsl:with-param name="nom">tata</xsl:with-param>
>   </xsl:call-template>
> </xsl:variable>
> 
> I have the node that i would have BUT i can't apply
> 
> <xsl:for-each select="$tata">
>   <xsl:value-of select="./value"/>
> </xsl:for-each>
> 
> because it result with a null value, the transformation don't return a
> value.

The variable $tata is a result tree fragment. In XSLT 1.0 the operand of
xsl:for-each must be a node-set, so this construct should fail. Some
products implement a feature of the XSLT 1.1 and 2.0 working drafts, whereby
$tata is treated as the root node of a tree. In this case you wouldn't get
an error, but you would get no data back, because this root node does not
have a child element named "value". You would be closer if you used copy-of
rather than value-of; you could then do xsl:value-of select="*/VALUE" (the *
picks up a node called STRUCT or SCALAR).


Michael Kay

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.