xsl-list
[Top] [All Lists]

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

2008-10-24 08:34:09
Ken,

Many thanks for your help - this is now working and I've got two-pass processing working on my full transform.

Now I've got a further problem - the second pass is inserting the values in the id attributes, but it's dropping any other attributes that are in the result of pass1. It's nothing to do with the two-pass process since the same problem occurs if I run just the second pass. So I want to transform this:
<newnode id="" x="539">
  <name>Root of my tree</name>
  <newnode id="" x="267" y="tomjones">
     <name>Child of root</name>
  </newnode>
  <newnode id="">
     <name>Another child of root</name>
     <newnode id="" price="4.99">
        <name>Grandchild of root</name>
     </newnode>
  </newnode>
  <newnode id="">
     <name>Yet another child of root</name>
  </newnode>
</newnode>

into this:
<newnode id="1" x="539">
  <name>Root of my tree</name>
  <newnode id="2" x="267" y="tomjones">
     <name>Child of root</name>
  </newnode>
  <newnode id="3">
     <name>Another child of root</name>
     <newnode id="4" price="4.99">
        <name>Grandchild of root</name>
     </newnode>
  </newnode>
  <newnode id="5">
     <name>Yet another child of root</name>
  </newnode>
</newnode>

My transform is:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="*[(_at_)id]">
    <xsl:copy>
      <xsl:attribute name="id">
        <xsl:number level="any" count="*[(_at_)id]"/>
      </xsl:attribute>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

It adds the values to the id attributes but omits all the other attributes.

What do I have to do to this to get it to copy all the attributes to the output file? I'm sure this is trivial, but everything I've tried has either had no effect or caused an error message.

Thanks - Rowan


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