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

RE: AW: Accessing values in a node-set using XPATH

Subject: RE: AW: Accessing values in a node-set using XPATH
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 11 Nov 2008 11:21:47 -0000
RE:  AW: Accessing values in a node-set using XPATH
Firstly, please don't use this:

<xsl:variable name="x">
  <xsl:value-of select="y"/>

when you really want

<xsl:variable name="x" select="y"/>

If you're paid for your coding by the line, you will earn three times as
much writing it the first way, but in every other respect the second
alternative is vastly preferable. If y is a string, you want the string, not
a new temporary document containing a document node whose child is a text
node whose string value is the string.

> <xsl:template name="print">
>    <xsl:param name="pos"/>
>    <xsl:variable name="xpath">
>       <xsl:value-of
> select="document('config-szenario.xml')/config/Line/field[posi
> tion() = $pos]"/>
>    </xsl:variable>
>    <xsl:if test="$xpath">

Here's another reason why you should use the select="y" form. This test will
always succeed: $xpath is a document node and the effective boolean value of
a node is always true, regardless of its content.

> However is there a possibility to perform this also on a
> nodeset? I would like to pass a variable (e.g. comparing) and
> then call dyn:evaluate like shown below. However it raises an
> error. It this somehow possible?
> <xsl:value-of select="dyn:evaluate($comparing/$xpath)"/>

Different implementations of dyn:evaluate() may differ in detail on this.
The safest bet is probably to assume that you can't pass variables into the
dynamic XPath expression, but you can pass the context node. So in XSLT 2.0
you could write

<xsl:value-of select="$comparing/dyn:evaluate($xpath)"/>

while in 1.0 it would have to be

<xsl:for-each select="$comparing">
   <xsl:value-of select="dyn:evaluate($xpath)"/>

Michael Kay

Current Thread


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.
First Name
Last Name
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.