gpt4 book ai didi

xpath - 使用正则表达式模式检查 XML 元素的属性值

转载 作者:行者123 更新时间:2023-12-03 17:13:23 27 4
gpt4 key购买 nike

我有这个代码,它不起作用。

我想遍历所有 p body 下的元素元素并查找名为 object 的元素.然后使用 match()在属性节点数据中查找特定模式的函数。

<xsl:template match="/xhtml:html/xhtml:body//xhtml:p">
<xsl:for-each select="xhtml:object[matches(@data,'*mov$')]">
<halloMovie><xsl:value-of select="@data"/></halloMovie>
</xsl:for-each>
</xsl:template>

使用 match() 执行时出现错误消息

[xslt] : Fatal Error! Could not compile stylesheet Cause: Error checking type of the expression 'funcall(matches, [step("attribute", 17), literal-expr(v$)])'.



如果我在 contains() 中使用以下行起作用的功能。
<xsl:for-each select="xhtml:object[contains(@data,'.mov')]">

我究竟做错了什么?

最佳答案

matches函数需要 XPath 2.0(因此需要 XSLT 2.0)或更高版本,XSLT 1.0 中不支持正则表达式。

如果您只想检查该值是否以“.mov”结尾,您可以使用 substring 函数

substring(@data, string-length(@data) - 3) = '.mov'

(XPath 1.0 有 starts-with 但您需要 2.0 才能获得 ends-with )。

关于xpath - 使用正则表达式模式检查 XML 元素的属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28625872/

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