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

Array of all X elements in XML

Subject: Array of all X elements in XML
From: Jorge <chocolate.camera@xxxxxxxxx>
Date: Mon, 28 May 2012 00:21:23 +0200
 Array of all X elements in XML
Hi,

When I learned that the Xpath path "A//B" returns all B nodes in A context, I
assumed that appending an N index number would return the Nth node in that
list.

I.e. using the following snippet as the source XML to be transformed

> <article>
> 	<p>1st paragraph</p>
> 	<p>2nd paragraph</p>
> </article>
> <article>
> 	<p>3rd paragraph</p>
> 	<p>4rth paragraph</p>
> </article>

I assumed //p[2] would return only "<p>2nd paragraph</p>", whatever the
hierarchy looks like.

I now see I was wrong, and instead returns all nodes on the Nth position in
their respective tree level. (i.e. returns "<p>2nd paragraph</p>, <p>4rth
paragraph</p>").

In order to mimic the behavior I originally expected, I can only think of
creating a variable, assigning all p element nodes to it, and from then on use
that variable to get the single Nth node inside the variable's context.

I.e., if I wanted to get the "4rth paragraph" irrespectively of the tree, I
could use this XSLT

> <xsl:variable name="PARAGRAPHS" select="//p"/>
> <copy-of>
> 	<xsl:value-of select="$PARAGRAPHS/p[4]"/>
> </copy-of>

Is there any other way more straight?

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.