This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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




"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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]