0

I have xml file with such structure:

...
<outer>
   ...
   <inner/>
   ...
</outer>
...
<outer>
   ...
   <inner/>
   ...
</outer>
...

Instead of "..." there exist other elements. How one could enumerate <inner/> elements using xslt? The output should be:

...
<outer>
   ...
   <inner>1</inner>
   ...
</outer>
...
<outer>
   ...
   <inner>2</inner>
   ...
</outer>
...

EDIT 1. What if we need to count and copy only <outer copy="1">? This doesn't work:

4

2 回答 2

3

Use xsl:number:

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="outer/inner">
    <xsl:copy>
      <xsl:number level="any"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
于 2012-06-13T14:04:21.060 回答
0

I'm not sure if this is what you are looking for:

<xsl:for-each select="outer/inner">

</xsl:for-each>

于 2012-06-13T13:46:25.190 回答