Xslt 1.0 repeat transformation

I have the following scenario:

<a>
  <b>
     <a>
       <b></b>
     </a>
  </b>
</a>

What I would like to do is to delete the all the 'a' nodes where the 'b' node has no children.

As you can see there is a pattern. If I delete the inner 'a' node, the result which is shown below should be deleted again.

<a>
   <b></b>
</a>

What I have until now looks like this:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="node()">
    <xsl:copy>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="a[b[not(*)]]"/>
</xsl:stylesheet>

Is there any way in which I can make my current xslt transformation to repeat itself so that it can check again for the pattern and delete it? I mention that I do not know how many times the pattern will repeat itself.

Answers


If I am guessing (!) correctly, you want to do:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="a[not(.//b[node()[not(self::a)]])]"/>

</xsl:stylesheet>

This removes any a element that doesn't have any b descendants with child nodes other that a.


Need Your Help

backbone set module going into infilinte loop - backbon

javascript jquery backbone.js

I am not getting why my page is going on infinite loop.

Type in a combobox and find like values vb.net

vb.net combobox

Currently I have a dropdown list that has thousands of values. Right now when I type in the dropdown list it will find the values that start with the letters I have typed and filter the list. Is it