gpt4 book ai didi

xslt - 有没有办法在覆盖该属性集时从 XSLT 属性集中删除所有属性?

转载 作者:行者123 更新时间:2023-12-02 22:06:16 24 4
gpt4 key购买 nike

我正在使用一些第三方 XSLT,它们大量使用属性集将 XML 转换为各种形式的 XSL:FO。示例:

笔记.xsl:

<xsl:template match="note">
<fo:block xsl:use-attribute-sets="noteAttrs">
<!-- This is a pretty big template with lots of xsl:choose/xsl:if/etc. -->
</fo:block>
<xsl:template>

<xsl:attribute-set name="noteAttrs">
<xsl:attribute name="margin-left">10px</xsl:attribute>
<xsl:attribute name="margin-right">8px</xsl:attribute>
<xsl:attribute name="margin-top">5px</xsl:attribute>
<xsl:attribute name="font-size">10pt</xsl:attribute>
<!-- several other attributes -->
</xsl:attribute>

我的想法是导入此 XSLT,重新定义我认为合适的属性集。如果我只需要为给定的 .fo 文档使用不同的字体大小...

<xsl:import href="notes.xsl"/>
<xsl:attribute-set name="noteAttrs">
<xsl:attribute name="font-size">12pt</xsl:attribute>
</xsl:attribute>

问题是有时我需要彻底删除属性(即我从包​​含的 fo:block 继承),或者给定的 fo 文档将非常不同以至于重新开始而不是合并会更容易我的属性集来自 notes.xsl。 XSLT 2.0 中有没有一种方法可以做到这一点,而无需为注释复制整个模板并在 fo:block 上指定不同的属性集?我想我希望能够做这样的事情:

<xsl:import href="notes.xsl"/>
<xsl:attribute-set name="noteAttrs" merge_with_imported_attr_set="false">
<xsl:attribute name="font-size">12pt</xsl:attribute>
</xsl:attribute>

我不能立即切换到 XSLT 3.0 处理器,但如果 3.0 中有新的东西可以实现这一点,我很想知道。

谢谢!

最佳答案

属性集的使用不是很广泛,为了回答您的问题,我不得不查看规范以刷新内存。我认为没有任何方法可以实现您想要的;您不能真正覆盖导入样式表中的属性集,您只能对其进行补充。在设计良好的 XML 词汇表中,通常会有一个属性值,您可以设置它等同于省略该属性,但如果不是这种情况,那么您就会陷入困境。

关于xslt - 有没有办法在覆盖该属性集时从 XSLT 属性集中删除所有属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16067702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com