How To Copy All Nodes And Change The Value Of Certain Nodes



TODO:

Have you ever wanted to copy an XML document, but change certain node data during the copy?

 

SOLUTION:

 

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl">
  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
 
  <!-- copy your input verbatim -->
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*" />
    </xsl:copy>
  </xsl:template>

  <!-- Now copy book id now appending the prefix to the data -->
  <xsl:template match="/Books/Book/BookID">
    <BookID>SomeValue-<xsl:apply-templates select="@*|node()"/></BookID>
  </xsl:template>

</xsl:stylesheet>

 

 

NOTES:

There are no notes on this topic.