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

RE: Document function (was Getting an error with a va

Subject: RE: Document function (was Getting an error with a variable)
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 29 Jul 2006 10:26:31 +0100
RE:  Document function (was Getting an error with a  va
> This is a snippet of code. Am I on the right 
> track or is there a more efficient way?
> 
>   <xsl:for-each
> select="/legs/competition/leg/Competitor[../../@name=$paramVal1]">
>   <tr>
>     <td><xsl:value-of select="@no"/></td>
> 	<xsl:variable name="cNum">
> 	    <xsl:value-of select="@no"/>
> 	</xsl:variable>

Never do this. Write

<xsl:variable name="cNum" select="@no"/>

There's no need to construct a new result tree fragment when you only want a
reference to a node. (And no need for three lines of code when one would do
- XSLT is verbose enough without making it worse).

>     <td><xsl:value-of
> select="document('EntryList.xml')/entrylist/competition/entry/
> @driverSurname
> [../@no=$cNum]"/>
>     <td><xsl:value-of
> select="document('EntryList.xml')/entrylist/competition/entry/
> @coDriverSurna
> me[../@no=$cNum]"/>

You're less reliant on the optimizer if you define a variable:

<xsl:variable name="entry" 
 
select="document('EntryList.xml')/entrylist/competition/entry[@no=$cNum]"/>

then select="$entry/@driverSurname" and select="$entry/@codriverSurname"

Note also, predicates can appear on steps in a path expression other than
the last. You can write

document('EntryList.xml')/entrylist/competition/entry[@no=$cNum]/@driverSurn
ame

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

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.