简体   繁体   English

Xslt 1.0重复转换

[英]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. 我想做的是删除所有“ a”节点,其中“ b”节点没有子节点。

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”节点,则应再次删除下面显示的结果。

<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? 有什么方法可以使当前的xslt转换重复自身,以便它可以再次检查该模式并将其删除? I mention that I do not know how many times the pattern will repeat itself. 我提到我不知道该模式会重复多少次。

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 . 这消除了任何a不具有任何元素b其他与子女后代节点是a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM