我有这个 xml 文件:
<w>
<!-- many text nodes like below-->
<text attr1="3" width="100">This is a sentence.</text>
<text attr1="5" width="110">Another sentence, this time with a % in it.</text>
<text attr1="9" width="40">Some text.</text>
<text attr1="3" width="49">Other text.</text>
<text attr1="1" width="90">Again some text</text>
<!-- many text nodes like above-->
</w>
我想用 ' %
' 折叠元素的所有后续节点,这些节点在其文本节点中具有 -width
属性lower than 50
,并用 包围整个组<tag1>
,使其看起来像这样:
<w>
<!-- many text nodes like below-->
<text attr1="3" width="100">This is a sentence.</text>
<text attr1="5" width="110">Another sentence, this time with a
<tag1>% in it. Some text. Other text.</tag1>
</text>
<text attr1="1" width="90">Again some text</text>
<!-- many text nodes like above-->
</w>
我已经用这个模板试过了:
<xsl:choose>
<xsl:when test="contains(.,'%') and following-group|@width <50">
<!-- I cannot choose current-group(), it generates a output with no tag1's
at all -->
<tag1><xsl:value-of-select="."/></tag1>
</xsl:when>
</xsl:choose>
但这只会将包含 s 的行放在%
s 中<tag1>
。我不明白为什么我不能选择我在测试中匹配的整个组。我也知道,即使它与整个事物相匹配,<tag1>
s 也会将整行包含在 中%
,但这是次要的。