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

Re: I mean self::* doesn't select attributes :(

Subject: Re: I mean self::* doesn't select attributes :(
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Wed, 25 Apr 2001 10:54:36 +0100
schematron get full path

"G. Ken Holman" wrote:
> 
> 
> This is an excerpt from pages 182/183 of my book:
>
Interesting - thank you.

Here's some code which had to solve a similar problem - it's intended to
generate a repeatable (same doc but different runs or different
processors) ID for any node in the XPath data model.

Replace the literal '+' characters with '/' characters and it should do
XPaths instead, though I haven't tested it!

Hope this helps!

Francis.

<!-- -->
<!-- repeatable-id maker -->
<xsl:template match="/" mode="schematron-get-full-path"/>
<xsl:template match="text()" mode="schematron-get-full-path">
  <xsl:apply-templates select="parent::*"
mode="schematron-get-full-path"/>
  <xsl:value-of select="concat('+text()[',
1+count(preceding-sibling::text()), ']')"/>
</xsl:template>
<xsl:template match="comment()" mode="schematron-get-full-path">
  <xsl:apply-templates select="parent::*"
mode="schematron-get-full-path"/>
  <xsl:value-of select="concat('+comment()[',
1+count(preceding-sibling::comment()), ']')"/>
</xsl:template>
<xsl:template match="processing-instruction()"
mode="schematron-get-full-path">
  <xsl:apply-templates select="parent::*"
mode="schematron-get-full-path"/>
  <xsl:value-of select="concat('+processing-instruction()[',
1+count(preceding-sibling::processing-instruction()), ']')"/>
</xsl:template>
<xsl:template match="@*" mode="schematron-get-full-path">
  <xsl:apply-templates select="parent::*"
mode="schematron-get-full-path"/>
  <xsl:value-of select="concat('+@', name())"/>
</xsl:template>
<xsl:template match="*" mode="schematron-get-full-path" priority="-0.5">
  <xsl:apply-templates select="parent::*"
mode="schematron-get-full-path"/>
  <xsl:text>+</xsl:text>
  <xsl:choose>
    <xsl:when test="count(. | ../namespace::*) =
count(../namespace::*)">
      <xsl:value-of
select="concat('+namespace::[',1+count(namespace::*),']')"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of
select="concat('+',name(),'[',1+count(preceding-sibling::*[name()=name(current())]),']')"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

 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.