【问题标题】:Exclude elements with certain attribute value from xsl:number从 xsl:number 中排除具有特定属性值的元素
【发布时间】:2017-04-26 18:11:39
【问题描述】:

我使用<xsl:number> 来计算<proceduralStep>。 (我用的是天线屋 6.2)

<xsl:number count="proceduralStep" from="content" level="multiple" format="1.1.1.1.1"/>

但我想排除任何具有属性@changeType='delete'的父或子的proceduralStep

XML 可能如下所示:

    <proceduralStep><para>Install This.</para></proceduralStep>
    <proceduralStep><para changeMark="1" changeType="delete">Delete this line.</para></proceduralStep>
    <proceduralStep><para>Continue with ths</para></proceduralStep>

    <proceduralStep><para><changeInline  changeMark="1" changeType="delete">And this line.</changeInline></para></proceduralStep>

    <proceduralStep><para>Continue with this</para></proceduralStep>
<revst changeMark="1" >
    <proceduralStep><para>Turn the screw....</para></proceduralStep>
    <proceduralStep><para>Hold assembly tool....</para></proceduralStep>
    </revst>

输出应该是这样的

    1.2.11 Install This
           Delete this line
    1.2.12 Continue with ths

另一个问题是当使用&lt;revst&gt; 作为&lt;proceduralStep&gt; 的包装器时,编号会重新开始:

    1.2.13 Continue with this
    1.2.1 Turn the screw....
    1.2.2 Hold assembly tool...

代替:

    1.2.13 Continue with this
    1.2.14 Turn the screw....
    1.2.15 Hold assembly tool...

&lt;xsl:number count="ancestor-or-self::*[changeType!='delete']" from="content" level="multiple" format="1.1.1.1.1"/&gt;

抛出错误:在谓词之外的匹配模式中只允许使用 'child' 和 'attribute' 轴

【问题讨论】:

    标签: xml xslt xsl-fo


    【解决方案1】:

    但我想排除任何有父母或孩子的程序步骤 带属性@changeType='delete'

    要计算proceduralStep,不包括那些具有属性@changeType='delete' 的子节点,请使用:

    count="proceduralStep[not(*/@changeType = 'delete')]"
    

    要将其扩展到父节点,您可以使用:

    count="proceduralStep[not(*/@changeType = 'delete' or parent::*/@changeType = 'delete')]"
    

    请注意,a!=bnot(a=b) 不同。

    【讨论】:

    • 非常感谢!这很好用。我不明白为什么a!=b 不等于not(a=b)(我仍然遇到包装&lt;revst&gt;&lt;proceduralStep&gt;&lt;/proceduralStep&gt;&lt;/revst&gt; 正在重新启动该级别的编号的问题。)
    • 1. 因为当a 不存在时,a!=b返回 true。 2. 我怀疑你想使用level="any"。很难确定使用您的示例。
    • level=multiple 是嵌套步骤所必需的,所以我会处理它。太糟糕了,因为level="any" 编号正确。你真的很有帮助,迈克尔,我很感激!
    • 这很接近 &lt;xsl:number count="revst[not(@changeType = 'delete')] | proceduralStep[not(*/@changeType = 'delete' or parent::*/@changeType = 'delete')]" from="content" level="multiple" format="1.1.1.1.1"/&gt; 但是当使用 revst 时,编号是 1.14、1.15.1、1.15.2、1.16 而不是 1.14、1.15、1.16、1.17
    • 您需要发布一个可重现的示例(包括输入和预期输出)——最好是在一个新问题中。
    猜你喜欢
    • 2018-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-02
    • 2012-11-30
    • 1970-01-01
    相关资源
    最近更新 更多