Subject: Re: Absolute-path/index challenge From: Steve Tinney <stinney@xxxxxxxxxxxxx> Date: Thu, 20 Jan 2000 21:37:25 -0500 |
Unless I'm missing something, this is not so hard, is it? I added an attribute to your tree to give me something to activate on. tree.xml: <A> <B> <C/> </B> <B> <C/> <C activate="yes"/><!--call template with current() here --> </B> <B> </B> </A> showpath.xsl: <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="*"> <xsl:if test="./@activate='yes'"> <xsl:for-each select="ancestor-or-self::*"> <xsl:call-template name="print-step"/> </xsl:for-each> </xsl:if> <xsl:apply-templates select="*"/> </xsl:template> <xsl:template name="print-step"> <xsl:value-of select="name()"/> <xsl:text>:</xsl:text> <xsl:value-of select="1+count(preceding-sibling::*)"/> <xsl:text>.</xsl:text> </xsl:template> </xsl:stylesheet> Result: A:1.B:2.C:2. Steve Thomas E Enebo wrote: > > As an extension of the position() of parent question from digest 480, > I have a challenge. How can a template be created, such that it will > print out the complete path of current node from the root? As an > example: > > <A> > <B> > <C/> > </B> > <B> > <C/> > <C/> <--- calling a template with current() here... > </B> > <B> > </B> > </A> > > will yield > > A:1.B:2.C:2 > > Where the first part is the element name and the second part is it's > relative position with respect to all other nodes at the same level. > > I know I would need to create a named template that recurses passing > the parent to next invocation of template. I also know the end case > is when the current node is the root. > > To print the index I think I would use David Carlisles comment on > position > thread yesterday.. > > <xsl:value-of select="1+count(../preceding-sibling::*)"/> > > Anyone? > > -Tom > > -- > +--------http://www.tc.umn.edu/~enebo --------+-mailto:enebo@xxxxxxxxxx -+ > | Thomas E Enebo, Friend of the University | ???????????????????????? | > | Phone: (612) 237-4607 Fax: (???) ???-???? | ???????????????????????? | > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list -- ---------------------------------------------------------------------- Steve Tinney Babylonian Section * University of Pennsylvania Museum stinney@xxxxxxxxxxxxx Phila, PA. 215-898-4047 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Absolute-path/index challenge, David Carlisle | Thread | Re: Absolute-path/index challenge, G. Ken Holman |
name collisions, disambiguation, megan adams | Date | Re: Am I missing something?, Steve Tinney |
Month |