Rectangle 27 1

xml Copy only the nodes where the name contains "a"?


<?xml version="1.0" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="*[contains(name(), 'a')]/*[contains(name(), 'a')] | /*[contains(name(), 'a')]">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="*">
  </xsl:template>

</xsl:stylesheet>
<a>
  <z x="x">
    <aa>z
      <ade>Another case</ade>
    </aa>
  </z>
</a>

<z> is to be skipped, but should we do to his contents? Regarding your rules, <ade> should be output because it a child of <aa>, but <aa> is not processed at all because its parent is z (skipped).

Here's a small stylesheet that will lead you to the expected result.

However I think it's not really clearly stated for the case of the text within an element that has to be skipped.

It work perfectly! Since it is an assignment, even I don't know what to do in the case presented, the only thing I had to do was understand how to do it for this particular case. That way I understand your code is that you check if any first, second and third child all contains "a" with a 0 to many match... Do I understand it well?

Morover, how should we process such a case:

Note