XSLT - Copy all other nodes, add 1 new node

Mr.Mega

New Member
I have created an XSLT and i was wondering how it is possible to copy all nodes between one set of tags, and add another tag at the bottom. I have created the XSLT that has all the logic for determining which tag to add, and what it should be called. However the issue i am now getting is that i can not copy all the other tags across too. Below are the files in question:XSLT\[code\]<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="/csvImportSchema"> <csvImportSchema> <xsl:for-each select="payload"> <payload> <xsl:copy-of select="@*"/> <xsl:variable name="ean"> <xsl:value-of select="ean"/> </xsl:variable> <xsl:for-each select="../product"> <xsl:if test="ean = $ean"> <productId><xsl:value-of select="article"/></productId> </xsl:if> </xsl:for-each> </payload> </xsl:for-each> </csvImportSchema> </xsl:template></xsl:stylesheet>\[/code\]INPUT\[code\]<?xml version="1.0" encoding="UTF-8"?><csvImportSchema> <payload> <test>1</test> <test2>2</test2> <test3>3</test3> <ean>1111111111</ean> <productId/> </payload> <product> <article>722619</article> <ean>1111111111</ean> </product></csvImportSchema>\[/code\]CURRENT OUTPUT\[code\]<?xml version="1.0" encoding="utf-8"?><csvImportSchema> <payload> <productId>722619</productId> </payload></csvImportSchema>\[/code\]DESIRED OUTPUT\[code\]<?xml version="1.0" encoding="UTF-8"?><csvImportSchema> <payload> <test>1</test> <test2>2</test2> <test3>3</test3> <ean>1111111111</ean> <productId>722619</productId> </payload></csvImportSchema>\[/code\]
 
Back
Top