[xsl] XSL/XPath to generate a list of ancestors?

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




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

    <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"/>

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