关于带有函数的XPath的问题(Question about XPath with functions in it)

编程入门 行业动态 更新时间:2024-10-22 07:39:23
关于带有函数的XPath的问题(Question about XPath with functions in it)

这是我之前线程的后续问题:

请帮助我理解这个XPath

我有一个XPath:

<xsl:value-of select="position()+count(preceding-sibling::*)-18"/>

目前我只能理解它的部分,比如position()。 另外,我知道前面的兄弟姐妹是在当前节点之前选择所有的兄弟姐妹,但是我不知道当他们像上面那样组合时语句的含义。

任何人都可以帮助理解这个XPath吗? 提前致谢。

this is a follow-up question of my previous thread:

Please help me on understanding this XPath

I have an XPath as:

<xsl:value-of select="position()+count(preceding-sibling::*)-18"/>

currently I can only understand the parts of it, like position(). Also, I know that preceding-sibling is to choose all siblings before the current node, but I have no idea what the statement mean when they get combined like above.

Could anyone give some help on understanding this XPath? thanks in advance.

最满意答案

除@Alejandro之外的所有答案都有相同的常见错误

这不是事实

preceding-sibling::*

选择所有前面的兄弟节点。

它只选择所有前面的兄弟元素。

要选择所有前面的兄弟节点,请使用

preceding-sibling::node()

XPath中有这些类型的节点

XPath 2.0中的根节点 (表示为/ ),也表示为document-node()

元素节点 。 如<a/>

文本节点 。 在<a> Hello </a> ,文本节点是a的唯一子节点,其字符串值为“Hello”

评论节点 。 <!-- This is a comment-->

处理指令节点 。 <?someName I am a PI ?>

属性节点 。 在<ax="1"/> x是a的唯一属性。

命名空间节点 。 <a xmlns:my="my:namespace"/> a有一个名称空间节点,其值为“my:namespace”和名称(前缀) my

前5种节点可以使用preceding-sibling:: axis选择

preceding-sibling::node()

选择种类1至5的所有兄弟节点。

preceding-sibling::*

选择兄弟之前的所有元素

preceding-sibling::someName

选择在兄弟姐妹之前名为“someName”的所有元素

preceding-sibling::text()

选择兄弟之前的所有文本节点(在混合内容中有用)

preceding-sibling::comment()

选择兄弟之前的所有评论节点。

preceding-sibling::processing-instruction()

选择所有前面的PI是兄弟

preceding-sibling::processing-instruction('someName')

选择所有先前的PI为“someName”的兄弟。

All answers with the exception of @Alejandro 's have the same common fault:

It is not true that:

preceding-sibling::*

selects all preceding-sibling nodes.

It only selects all preceding-sibling elements.

To select all preceding-sibling nodes use:

preceding-sibling::node()

There are these kind of nodes in XPath:

The root node (denoted as /), also denoted as document-node() in XPath 2.0

Element nodes. such as <a/>

Text nodes. In <a> Hello </a> the text node is the only child of a and has a string value of " Hello "

Comment nodes. <!-- This is a comment-->

Processing instruction nodes. <?someName I am a PI ?>

Attribute nodes. In <a x="1"/> x is the only attribute of a.

Namespace nodes. <a xmlns:my="my:namespace"/> a has a namespace node with value "my:namespace" and name (prefix) my

Nodes of the first 5 kinds can be selected using the preceding-sibling:: axis:

preceding-sibling::node()

selects all sibling nodes of kind 1 to 5.

preceding-sibling::*

selects all element preceding siblings

preceding-sibling::someName

selects all elemens named "someName" preceding siblings

preceding-sibling::text()

selects all text nodes preceding siblings (useful in mixed content)

preceding-sibling::comment()

selects all comment node preceding siblings.

preceding-sibling::processing-instruction()

selects all preceding siblings that are PIs

preceding-sibling::processing-instruction('someName')

selects all preceding siblings that are PIs and are named "someName".

更多推荐

XPath,理解,position,preceding-sibling,电脑培训,计算机培训,IT培训"/> <meta name

本文发布于:2023-07-23 00:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1225186.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   XPath   functions   Question

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!