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

Re: ### Outputting the "full path". Is this possible ?? ###

Subject: Re: ### Outputting the "full path". Is this possible ?? ###
From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
Date: Thu, 25 May 2000 18:04:23 +0100
xsl value of full path
Jonathan,

>Considering this xml:
>
><departments>
>	<employees>
>		<name>Joe Shmo</name>
>	</employees>
></employees>
>
>If the current node is "name", is there a simple XSL: way of outputting the
>"full path", ie:
>"departments/employees/name/Joe Shmo"

The 'full path' that you're describing are the names of the ancestor
elements of the current node, plus the current node, plus the current
node's value, separated by '/'s.

There are two ways of doing this: iteration and recursion.  I'm going to
show you  iteration because it keeps everything in one place.  You do
iteration using an xsl:for-each element.  We want to iterate over the list
of the ancestor elements of the current node, but we also want to include
the current node, and helpfully there is an XPath axis that enables us to
do just that: ancestor-of-self.  We don't care what the ancestor elements
are called.  So:

<xsl:for-each select="ancestor-of-self::*">
  ...
</xsl:for-each>

OK, so for each of those nodes we want to output the name of the node,
followed by a forward shash and no whitespace:

<xsl:for-each select="ancestor-of-self::*">
  <xsl:value-of select="name()" /><xsl:text>/</xsl:text>
</xsl:for-each>

Once we've outputted the information about the ancestor elements, we want
to round it off with information about the value of the current node:

<xsl:value-of select="." />

So, the complete template is:

<xsl:template match="name">
  <xsl:for-each select="ancestor-of-self::*">
    <xsl:value-of select="name()" /><xsl:text>/</xsl:text>
  </xsl:for-each>
  <xsl:value-of select="." />
</xsl:template>

Easy, eh?

Hope that helps,

Jeni

Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 ? Fax 0115 9061304 ? Email
jeni.tennison@xxxxxxxxxxxxxxxx



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.