XSLT to copy one node value and create a new node

70 views
Skip to first unread message

Sathish Kumar

unread,
Apr 15, 2016, 5:40:15 AM4/15/16
to XSLT

Can someone guide me on how to write a XSLT1.0 to create the output as below? <csvImportSchema> <payload> <test>**COPY VALUE**</test> <test2>2</test2> <test3>3</test3> <ean>1111111111</ean> <productId/> </payload> </csvImportSchema>

to

<csvImportSchema> <payload> <test>COPY VALUE</test> <test2>2</test2> <test3>3</test3> <ean>1111111111</ean> <productId/> **<copied>COPY VALUE</copied>** </payload> <csvImportSchema>

Shaun Roe

unread,
Apr 15, 2016, 8:03:12 AM4/15/16
to speed...@gmail.com, XSLT

RTFM is the first answer which comes to mind; but with some generous assumptions, try this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   
<xsl:template match="csvImportSchema">
       
<csvImportSchema>
       
<xsl:apply-templates/>
        
</csvImportSchema>
   
</xsl:template>
   
<xsl:template match="payload">
       
<payload>
   
<xsl:apply-templates/>
       
<copied><xsl:value-of select="test"/></copied>
        
</payload>
   
</xsl:template>
   
<xsl:template match="*">
   
<xsl:copy-of select="."/>
   
</xsl:template>
</xsl:stylesheet>
Reply all
Reply to author
Forward
0 new messages