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

RE: xpath question, getting last instance of element

Subject: RE: xpath question, getting last instance of element
From: "Roger Glover" <glover_roger@xxxxxxxxx>
Date: Tue, 25 Feb 2003 13:28:10 -0600
xsl last instance of
***********************
INPUT
***********************
      <AAA>
           <BBB>
                <CCC/>
                <ZZZ>
                     <DDD/>
                     <DDD>
                          <EEE/>
                     </DDD>
                </ZZZ>
                <FFF>
                     <GGG/>
                </FFF>
           </BBB>
           <XXX>
                <DDD>
                     <EEE/>
                     <DDD/>
                     <CCC/>
                     <FFF/>
                     <FFF>
                          <GGG/>
                     </FFF>
                </DDD>
           </XXX>
           <CCC>
                <DDD>this is the one I want</DDD>
           </CCC>
      </AAA>

***********************
TRANSFORM
***********************
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text"/>

<xsl:template match="/">
    <xsl:apply-templates select="(//DDD)[position() = last()]"/>
                            <!-- ^^^^^^^ note the parentheses -->
</xsl:template>

</xsl:transform>

***********************
OUTPUT
***********************
this is the one I want

I hope this helps!

-- Roger Glover


Alan Stein wrote:

> I'm trying to figure out how to select the final instance of "DDD" in the
> following example, but since the predicate refers to the
> element's relative
> position to its neighbors, I am having trouble formulating an xpath which
> would take the last position with respect to the root of the document.
>
> Can someone shed light on this (possibly simple) question?



 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.