xsl-list
[Top] [All Lists]

Re: Getting the XPath of a node

2002-09-04 02:22:29
Dennis wrote:
Hi All,

Is there any way to get the XPath of a particular
element and attribute in match template???

Say if I have following XML:
<Person id="12345">
  <Name>Dennis</Name>
  <Company>Netscape</Company>
  <Address>Mountain View</Address>
  <Email>dennis(_at_)netscape(_dot_)com</Email>
</Person>

----The XSL to print XPath---
<xsl:template match="Company">
//Print the XPath of Company as /Person/Company
</xsl:template>
More templates corresponding to each element.

How do I do this...any thoughts???

  <xsl:for-each select="ancestor::*">
    <xsl:value-of select="concat('/',name())"/>
  </xsl:for-each>
  <xsl:value-of select="concat('/',name())"/>

If the current node is an attribute, change that last '/' to '/@'

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/

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



<Prev in Thread] Current Thread [Next in Thread>