Question

I am trying to develop an XSLT stylesheet which will transform an xml into another by keeping in view:

  1. By default the stylesheet should display nothing for each element (not even the text).
  2. If there is an explicit template match for an element, then copy that element, it's attributes and all its sub-elements (and their attributes).

In other words, identity transform only the elements explicitly specified.

Was it helpful?

Solution

Well, to do nothing for most, surely something like:

<xsl:template match="/*">
  <xsl:copy>
    <xsl:apply-templates select="*"/>
  </xsl:copy>
</xsl:template>
<xsl:template match="*">
    <xsl:apply-templates select="*"/>
</xsl:template>

Then add matches for what you do want:

<xsl:template match="Foo | Bar">
    <xsl:copy-of select="."/>
</xsl:template>

However, it seems like a very unusual requirement. Normally you simply use matches that navigate to the known content through knowledge of the xml.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top