关于包含函数的 XPath 的问题 [英] Question about XPath with functions in it

查看:24
本文介绍了关于包含函数的 XPath 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

请帮助我理解这个 XPath

我有一个 XPath:

I have an XPath as:

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

目前我只能理解它的一部分,比如 position().另外,我知道previous-sibling 是选择当前节点之前的所有兄弟姐妹,但是我不知道当它们像上面一样组合时的语句是什么意思.

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.

有人可以帮助理解这个 XPath 吗?提前致谢.

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

推荐答案

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

事实并非如此:

preceding-sibling::*

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

selects all preceding-sibling nodes.

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

It only selects all preceding-sibling elements.

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

preceding-sibling::node()

XPath 中有这些类型的节点:

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

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

元素节点.比如

文本节点.在 中Hello </a> 文本节点是 a 的唯一子节点,并且字符串值为Hello"

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

评论节点.<!-- 这是注释-->

处理指令节点.

属性节点.在中,xa的唯一属性.

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

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

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

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

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

preceding-sibling::node()

选择所有类型为 1 到 5 的兄弟节点.

selects all sibling nodes of kind 1 to 5.

preceding-sibling::*

选择所有兄弟元素之前的元素

selects all element preceding siblings

preceding-sibling::someName

选择所有在兄弟姐妹之前名为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()

选择所有前面的 PI 兄弟

selects all preceding siblings that are PIs

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

选择所有前面的 PI 并命名为someName"的兄弟.

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

这篇关于关于包含函数的 XPath 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆