[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?
I think this could be simple to solve with XSLT 2.0. Below is the working stylesheet: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="/"> <result> <xsl:apply-templates select="//*[@name][not(@name = 'root')]" /> </result> </xsl:template> <xsl:template match="*"> <fullName> <xsl:value-of select="string-join(ancestor-or-self::*[not(@name = 'root')]/@name,'.')" /> </fullName> </xsl:template> </xsl:stylesheet> This when applied to the given XML, produces output: <?xml version="1.0" encoding="UTF-8"?> <result> <fullName>a1</fullName> <fullName>a1.a2</fullName> <fullName>a1.a2.a3</fullName> <fullName>b1</fullName> <fullName>b1.b2</fullName> </result> On 5/12/08, Nathan Potter <ndp@xxxxxxxxxxxxxxxxxxxx> 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? > > > > 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> -- Regards, Mukul Gandhi
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|