You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Cory Isaacson <ci...@capita2.com> on 2001/01/07 22:07:41 UTC

xsl:copy Question

I want to sort a section of an input document, and copy it out, including
all attributes into another DOM. This is using Xalan2.

I tried this type of thing, using 'xsl:copy' which follows the examples and
the book I have and spec as best I can tell:

  <xsl:template match="/">
    <topOutputNode>
    <xsl:apply-templates select="/node1/node2"/>
    </topOutputNode>
  </xsl:template>

  <xsl:template match="node1/node2">
    <xsl:for-each select="./node3">
      <xsl:sort order="ascending" data-type="number"
select="./node4[@attr1='test']"/>

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

    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

This produces output which contains all the values, but not the complete XML
syntax (i.e., exact copies of the original input).

However, when I use 'xsl:copy-of' like this, it works fine, but doesn't seem
to be the correct use of this per the XSLT spec:

  <xsl:template match="/">
    <topOutputNode>
    <xsl:apply-templates select="/node1/node2"/>
    </topOutputNode>
  </xsl:template>

  <xsl:template match="node1/node2">
    <xsl:for-each select="./node3">
      <xsl:sort order="ascending" data-type="number"
select="./node4[@attr1='test']"/>

        <node3>
          <xsl:copy-of select="./@*"/>

          <xsl:for-each select="./node4">

            <node4>
              <xsl:copy-of select="./@*|text()"/>
            </node4>

          </xsl:for-each>
        </node3>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

Any help is appreciated.

Thanks,

Cory