Copy subset of xml input using xslt
- by mdfaraz
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.