Posts

Showing posts from March, 2011

Filter XML elements by their namespace using XSLT

XSL Transformations (XSLT) is a powerful tool that can do much chore for us developers. Occasionally, XSLTs can compete with the other tools intended to transform XML. Look, for example, at the snippet that follows:
<xsl:templatematch="o:*" />
It strips out all the elements that are defined in the namespace referenced by alias o.
ExplanationA normal template expression has a format similar to the one of below:
<xsl:templatematch="author-group">
  <xsl:apply-templatesselect="author" />
</xsl:template>
This example processes all the author children of the author-group. By default, the XSLT processor processes each matched element only once. After an author-group element is selected, the processor outputs the author children of the matched element to XML. So, if the xsl:apply-templates element is omitted, the children of the source element are skipped during the transformation.