Copy subset of xml input using xslt
Posted
by
mdfaraz
on Stack Overflow
See other posts from Stack Overflow
or by mdfaraz
Published on 2012-03-21T22:46:04Z
Indexed on
2012/03/21
23:30 UTC
Read the original article
Hit count: 171
I need an XSLT file to transform input xml to another with a subset of nodes in the input xml. For ex, if input has 10 nodes, I need to create output with about 5 nodes Input
<Department diffgr:id="Department1" msdata:rowOrder="0">
<Department>10</Department>
<DepartmentDescription>BABY PRODUCTS</DepartmentDescription>
<DepartmentSeq>7</DepartmentSeq>
<InsertDateTime>2011-09-29T13:19:28.817-05:00</InsertDateTime>
</Department>
Output:
<Department diffgr:id="Department1" msdata:rowOrder="0">
<Department>10</Department>
<DepartmentDescription>BABY PRODUCTS</DepartmentDescription>
</Department>
I found one way to suppress nodes that we dont need XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Department/DepartmentSeq"/>
<xsl:template match="Department/InsertDateTime"/>
</xsl:stylesheet>
I need an xslt that helps me select the nodes I need and not "copy all and filter out what I dont need", since i may have to change my xslt whenever input schema adds more nodes.
© Stack Overflow or respective owner