xsl:copy-of

  • Copy the current context node together with any child nodes and attributes to the result document without converting it to a string.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template name="test">
        <xsl:copy-of select="."/>
      </xsl:template>
    </xsl:stylesheet>
    					
  • You can use xsl:copy-of instead of xsl:value-of to copy a node-set into a variable.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:variable name="contacts">
        <xsl:copy-of select="/contacts/*"/>
      </xsl:variable>
    
      <xsl:template name="test">
        <xsl:for-each select="$contacts">
          <xsl:apply-templates/>
        </xsl:for-each>
      </xsl:template>
    </xsl:stylesheet>