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

RE: Selecting the first node set

Subject: RE: Selecting the first node set
From: cknell@xxxxxxxxxx
Date: Sat, 05 Aug 2006 08:21:41 -0400
RE:  Selecting the first node set
On closer reading, you may have been asking for the first Value element anywhere in the document, regardless of how deep it may be nested. Here is an XSLT 2.0 solution. You could also do this with XSLT 1.0 using a node-set extension to create the variable.

  <xsl:variable name="Value-list">
  	<holder><xsl:copy-of select="//Value" /></holder>
  </xsl:variable>

  <xsl:template match="/">
    <xsl:copy-of select="$Value-list/holder/Value[1]" />
  </xsl:template>

-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     Fraser Goffin <goffinf@xxxxxxxxxxx>
Sent:     Sat, 05 Aug 2006 12:21:58 +0100
To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:   Selecting the first node set

Given the following simplified XML instance, can anyone suggest an 
expression that will return ONLY the 'Value' node containing <enum> children 
with values A, B and C. I can't rely on the name of the parent node of 
<Value> hence I have deliberately named these as UnknownNameX or any other 
intervening structure.

<Trade>
	<UnknownName1>
		<Value>
			<enum>A</enum>
			<enum>B</enum>
			<enum>C</enum>
		</Value>
	</UnknownName1>
	<UnknownName2>
		<Value>/Trade//Value[ancestor::Trade]</Value>
	</UnknownName2>
	<Treatment>
		<UnknownName3>
			<Value>
				<enum>D</enum>
				<enum>E</enum>
				<enum>F</enum>
			</Value>
		</UnknownName3>
	</Treatment>
</Trade>


/Trade//Value        - returns all 3 <Value> nodes
/Trade//Value[1]    - also returns all 3 <Value> nodes (why is that ?)
/Trade//Value[2]    - returns nothing (why is that ?)

Cheers

Fraser.

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.