Subject: Re: Function from-ancestors and parent element name. From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Wed, 08 Sep 1999 12:39:48 -0400 |
'********* I would like to have a count of the ' ******** parent of the name element ***** <xsl:value-of select="count(from-ancestors(parent(.)))"/>
T:\ftemp>type test.xml <?xml version="1.0"?> <test> <test attr="a"> <test attr="b"> <other attr="c"> <test attr="d"> <test attr="e"> <other attr="f"> <test attr="g"> <test attr="h"/> </test> </other> </test> </test> </other> </test> </test> </test>
T:\ftemp>type test.xsl <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
<xsl:template match="/*"> <!--don't report document element--> <xsl:apply-templates/> </xsl:template>
<xsl:template match="*"> <xsl:text>Element </xsl:text> <xsl:value-of select="@attr"/> <xsl:text> has parent </xsl:text> <xsl:value-of select="name(..)"/> <xsl:text>, being number </xsl:text> <xsl:value-of select="count(ancestor::*[name(.)=name(current()/..)])"/> <xsl:text>.
</xsl:text> <xsl:apply-templates/> </xsl:template>
T:\ftemp>call xsl test.xml test.xsl test.txt T:\ftemp>type test.txt Element a has parent test, being number 1. Element b has parent test, being number 2. Element c has parent test, being number 3. Element d has parent other, being number 1. Element e has parent test, being number 4. Element f has parent test, being number 5. Element g has parent other, being number 2. Element h has parent test, being number 6.
-- G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995) Website: XSL/XML/DSSSL/SGML services, training, libraries, products. Practical Transformation Using XSLT and XPath ISBN 1-894049-01-2 Next instructor-led training: 1999-09-24, 1999-11-08, 1999-12-05/06, 1999-12-07, 2000-02-27/28, 2000-05-11/12
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Function from-ancestors and parent , Stephane St-Denis | Thread | Character references, entities, XSL, Charity Hope |
RE: MSXML and Encoding, Ian Brockbank | Date | Character references, entities, XSL, Charity Hope |
Month |