xsl-list
[Top] [All Lists]

RE: Generating Sequential IDs

2005-07-05 04:41:33

I want to generate the sequence ids for all the nodes in the 
xml tree. For example my source xml looks like this..
      <A>
              <B></B>
              <C>
                      <D></D>
              </C>
              <E>
                      <F>
                              <G></G>
                      </F>
              </E>
      </A>

I want the output xml like..

      <A id=1>
              <B id=2></B>
              <C id=3>
                      <D id=4></D>
              </C>
              <E id=5>
                      <F id=6>
                              <G id=8></G>
                      </F>
              </E>
      </A>

Can any one give me the xslt code for this..

<xsl:template match="*">
        <xsl:copy>
                <xsl:copy-of select="@*"/>
                <xsl:attribute name="id">
                        <xsl:number level="any" count="*"/>
                </xsl:attribute>
                <xsl:apply-templates select="*"/>
        </xsl:copy>
</xsl:template>

...but if you are using Java I would recommend doing this using an
XMLFilter instead of XSLT.

cheers
andrew

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



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