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

XSL/XPath to generate a list of ancestors?

Subject: XSL/XPath to generate a list of ancestors?
From: Nathan Potter <ndp@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 12 May 2008 08:51:46 -0700
 XSL/XPath to generate a list of ancestors?
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?



XML:

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

Desired output:

<fullName>a1</fullName>
<fullName>a1.a2</fullName>
<fullName>a1.a2.a3</fullName>

<fullName>b1</fullName>
<fullName>b1.b2</fullName>


XSL:


    <xsl:template name="fullName">
        <fullName>
            <xsl:call-template name="fullNameWorker" />
        </fullName >
    </xsl:template>

    <xsl:template match="*" name="fullNameWorker" mode="fullName">
        <xsl:if test=".!=/">
            <xsl:apply-templates select=".." mode="fullName"/>
            <xsl:if test="..!=/">.</xsl:if>
            <xsl:value-of select="@name"/>
        </xsl:if>
    </xsl:template>

============================================================
Nathan Potter                 Oregon State University, COAS
ndp at coas.oregonstate.edu   104 Ocean. Admin. Bldg.
541 737 2293 voice            Corvallis, OR   97331-5503
541 737 2064 fax

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.