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

Re: current node attribute as predicate

Subject: Re: current node attribute as predicate
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 25 Oct 2002 11:49:12 +0100
select attribute of node

<xsl:template match="purchase">
		<xsl:variable name="ItemText">
			<xsl:value-of select="@item" />
		</xsl:variable>
		<xsl:copy-of select="/inventory/item[@itemcode=$ItemText]"
/>
	</xsl:template>




<xsl:variable name="ItemText">
			<xsl:value-of select="@item" />
		</xsl:variable>

makes ItemText into a variable which is a result tree fragment containing
a root node containing a text node with the value of the item attribute.
It is less to write and more efficient for the system if you go
<xsl:variable name="ItemText" select="@item" />
which makes ItemText a variable containing the attribute node.

It is often clearer if you do use a variable, as you did:

<xsl:copy-of select="/inventory/item[@itemcode=$ItemText]"/>

however if you don't want to use the variable you can use

<xsl:copy-of select="/inventory/item[@itemcode=current()/@item]"/>



Note however that if you are doing a lot of this then you are repeatedly
searching the entire tree finding items with the right itemcode.
If so it would be more efficient to make a key (if you only do it once
it probably doen't make any difference whether you use a key or not)

To use a key you would do at the top level

<xsl:key name="items" match="item" use="@itemcode"/>

then in the template you can jump straight to the right item


<xsl:template match="purchase">
	<xsl:copy-of select="key('items',@item)"/>
</xsl:template>


David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

 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.