xsl-list
[Top] [All Lists]

RE: [xsl] Identifier attribute (was: Re: [xsl] Creating Hierarchy)

2008-10-20 18:03:42
How would I generate these id/sequence values, either as a 
second pass, or as part of the first pass which generates 
this structure from the non-hierarchical source file?

<root>
    <a id="1">
        <b id="2">
            <e/>
        </b>
        <b id="3">
            <c id="4"/>
        </b>

I think the only way to do this is in a second pass. It then becomes fairly
easy:

Assuming you give the elements a blank id attribute in the first pass
(id=""), then in the second pass do

<xsl:template match="*[(_at_)id]" mode="pass2">
  <xsl:copy>
    <xsl:attribute name="id">
      <xsl:number level="any" count="*[(_at_)id]"/>
    </xsl:attribute>
    <xsl:apply-templates mode="pass2"/>
  </xsl:copy>
</xsl:template>

plus an identity template.

Michael Kay
http://www.saxonica.com/


--~------------------------------------------------------------------
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>
--~--