gpt4 book ai didi

xslt - 理解一些 xpath 表达式

转载 作者:行者123 更新时间:2023-12-02 11:47:35 26 4
gpt4 key购买 nike

有人可以帮我解密这个 xpath 表达式吗?

<xsl:template match="n1:table/@* | 
n1:thead/@* |
n1:tfoot/@* |
n1:tbody/@* |
n1:colgroup/@* |
n1:col/@* |
n1:tr/@* |
n1:th/@* |
n1:td/@*">

我相信它就在附近:

选择 n1:table 元素中的所有属性以及 n1:thead 元素中的所有属性以及 n1:tfoot 中的所有属性...等。

不过我真的不确定。

阅读本文是为了了解 xpath: http://www.w3schools.com/xpath/xpath_syntax.asp

愿意给我提示吗?

谢谢。

最佳答案

你基本上是对的。 | 是 XPath 的并集运算符:

来自http://www.w3.org/TR/xpath/#node-sets

The | operator computes the union of its operands, which must be node-sets

但在模式中,来自http://www.w3.org/TR/xslt#patterns

In a pattern, | indicates alternatives; a pattern with one or more | separated alternatives matches if any one of the alternative matches.

因此,模板匹配 n1 相对于当前上下文节点引用的命名空间中的 table、thead、tbody 等的任何属性。

您还需要使用如下内容来考虑源文档中是否存在命名空间:

<xsl:stylesheet 
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:n1="uri:something">

有关 XSLT 模板中的命名空间的更多信息:

http://radio-weblogs.com/0118231/stories/2006/10/03/xslt10PatternMatchingTipsForSourceDocumentsWithNamespaces.html

关于xslt - 理解一些 xpath 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5083093/

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