copy the entire block under another node - xslt transformation



I am new to XSL coding, here i am trying to take entire block of (result) nodes and placing inside another node called RESULTS... below is my xml and the xsl used.


But its not transforming the xml as expected...


Could anyone help me where am i doing it wrongly?


XML



<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="samplexslt.xsl"?>
<report>
<Header>
<RegNo>123</RegNo>
<EmrNo>op2145</EmrNo>
<BillNo>opcb1234-12</BillNo>
<Uhid>1209</Uhid>
<AdmissionDate>13-Jan-2014</AdmissionDate>
</Header>

<result>
<name>test1</name>
<desc1>abcdefghijklmnopqrstuvwxyz</desc1>
<desc2>description</desc2>
</result>
<result>
<name>test2</name>
<desc1>abcdefghijklmnopqrstuvwxyz</desc1>
</result>

<Footer>
<DoctorSign>Anand</DoctorSign>
</Footer>
</report>


XSLT



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/report">
<xsl:copy>
<xsl:apply-templates select="@*|node()[local-name() != 'result']"/>
</xsl:copy>
<notes>
<xsl:apply-templates select="result" />
</notes>
</xsl:template>

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>


Expected



<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="samplexslt.xsl"?>
<report>
<Header>
<RegNo>123</RegNo>
<EmrNo>op2145</EmrNo>
<BillNo>opcb1234-12</BillNo>
<Uhid>1209</Uhid>
<AdmissionDate>13-Jan-2014</AdmissionDate>
</Header>

<results>
<result>
<name>test1</name>
<desc1>abcdefghijklmnopqrstuvwxyz</desc1>
<desc2>description</desc2>
</result>
<result>
<name>test2</name>
<desc1>abcdefghijklmnopqrstuvwxyz</desc1>
</result>
</results>

<Footer>
<DoctorSign>Anand</DoctorSign>
</Footer>
</report>

No comments:

Post a Comment