I really just want to grab some XML, filter (by node name, some
attribute, etc) and generate a (filtered/smaller) version of that xml.
Do you think the xslt approach is the simplest ?
XSLT is a language that has been especially designed for transformation of tree-structured input. This is why it is probably the best and simplest for implementing such tasks.
Here is an example:
<nums>
<num>01</num>
<num>02</num>
<num>03</num>
<num>04</num>
<num>05</num>
<num>06</num>
<num>07</num>
<num>08</num>
<num>09</num>
<num>10</num>
</nums>
We want to produce from this XML document another document that has the same structure and element name/content, but contains only those num elements from the original document, whose valu is multiple of 3.
Here is the transformation to accomplish this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="num[not(. mod 3) = 0]"/>
</xsl:stylesheet>