gpt4 book ai didi

xslt - 如何在键之间共享匹配模式?

转载 作者:行者123 更新时间:2023-12-05 01:08:07 26 4
gpt4 key购买 nike

我有两个具有相同匹配模式的键。图案很长。模式本身并不重要;问题是冗长的重复:

  <xsl:key name="narrow-things-by-columnset" match="p | p-cont |
heading[not(parent::section or parent::contents) and not(parent::p)] |
language-desc | country-desc | graphic[not(parent::section or parent::contents)] |
block-quote | bulleted-list | blank-line |
bibliography | language-name-index | language-code-index | country-index | table-of-contents"
use="sileth:columnset-id(.)"/>

<!-- TODO: DRY: I would love to be able to share the above match pattern instead of
duplicating it. -->
<xsl:key name="narrow-things-by-section" match="p | p-cont |
heading[not(parent::section or parent::contents) and not(parent::p)] |
language-desc | country-desc | graphic[not(parent::section or parent::contents)] |
block-quote | bulleted-list | blank-line |
bibliography | language-name-index | language-code-index | country-index | table-of-contents"
use="sileth:section-id(.)"/>

DRY principal提醒我们,当我们有重复的数据时,我们会遇到保持多个副本同步的问题。事实上,这只是发生在我身上,导致了一个需要一段时间才能找到的错误。

所以我希望能够在两个键之间共享一个单一的、通用的匹配模式。 AFAIK 你不能使用变量来做到这一点。有没有其他方法可以做到?

最佳答案

我会用模式定义一个通用实体,并从两个位置引用它。所以样式表将开始

<!DOCTYPE xsl:stylesheet [
<!ENTITY match-elements "p | p-cont
| heading[not(parent::section or parent::contents)
and not(parent::p)]
| language-desc | country-desc
| graphic[not(parent::section or parent::contents)]
| block-quote | bulleted-list | blank-line
| bibliography | language-name-index | language-code-index
| country-index | table-of-contents">
]>
<xsl:stylesheet ...>
...

两个关键用途是:
<xsl:key name="narrow-things-by-columnset" 
match="&match-elements;"
use="sileth:columnset-id(.)"/>

<!-- DONE: DRY: Isn't is nice to be able to share the above
match pattern instead of duplicating it?
Hooray for general entities! -->

<xsl:key name="narrow-things-by-section"
match="&match-elements;"
use="sileth:section-id(.)"/>

关于xslt - 如何在键之间共享匹配模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17244436/

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