【问题标题】:XSLT looking to remove attribute then rematch the elementXSLT 希望删除属性然后重新匹配元素
【发布时间】:2021-09-15 22:38:22
【问题描述】:

所以我正在开发一个 XSLT 样式表,使用 RenderX 生成 pdf 作为输出。

目前我正在尝试找到一种方法,在元素具有特定属性时将一些简单的样式应用于元素,然后也想匹配它们的常规模板。我试图利用 xsl:copy,但我还没有设法让它工作,我不确定是否有可能实现我想要做的事情

<xsl:template match="node()[@ns:change='del' and not(@ns:changed='true')]" mode="#all" priority="1">
  <fo:inline text-decoration="line-through" color="#FF0000">
    <xsl:copy>
        <xsl:attribute name="ns:changed">true</xsl:attribute>
        <xsl:apply-templates select="." mode="#current"/>
    </xsl:copy>
  </fo:inline>
</xsl:template>

基本上我希望模板第一次被匹配到它被删除并被涂成红色,然后它能够​​匹配它的所有常规样式和格式。

我一直在尝试制作一个包罗万象的解决方案,因为我们有 100 个使用不同模式的模板,所以我能想到的另一个解决方案是检查每个单独的模板的属性,但我希望避免这种情况如果可能的话。

目前我遇到了它变得递归的问题(即属性未设置)或优先级=1的模板根本不匹配。

【问题讨论】:

    标签: xml xslt xsl-fo


    【解决方案1】:

    使用xsl:next-match(参见https://www.w3.org/TR/xslt20/#element-next-match)恢复常规处理:

    <xsl:template match="node()[@ns:change='del' and not(@ns:changed='true')]"
        mode="#all" priority="1">
      <fo:inline text-decoration="line-through" color="#FF0000">
        <xsl:next-match />
      </fo:inline>
    </xsl:template>
    

    如果在常规格式周围包裹fo:inline 还不够,您可以在xsl:next-match 上设置参数,然后使用常规模板中的参数值做正确的事情。

    【讨论】:

    • 完美的解决方案,在这完全符合我的需要之前,我没有听说过 xsl:next-match,谢谢 Tony
    猜你喜欢
    • 1970-01-01
    • 2020-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    相关资源
    最近更新 更多