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

Re: XSL/XPath to generate a list of ancestors?

Subject: Re: XSL/XPath to generate a list of ancestors?
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Mon, 12 May 2008 18:03:25 +0200
Re:  XSL/XPath to generate a list of ancestors?
Nathan Potter wrote:

I need to concatenate the "name" attributes of all of the parents for each element. All I could figure out was to use a recursive template. Is there a more straightforward way to accomplish this?


<Dataset name="root">
    <A name="a1">
        <A name="a2">
            <A name="a3" />
    <B name="b1">
        <B name="b2"/>

Desired output:



So you want to exclude the root element 'Dataset' although it has a name attribute. Then the following should do:


<xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
    <xsl:apply-templates select="*//*"/>

<xsl:template match="*">
<xsl:for-each select="ancestor-or-self::*[not(generate-id() = generate-id(/*))]/@name">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">


	Martin Honnen

Current Thread


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.
First Name
Last Name
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.