gpt4 book ai didi

xml - 使用 xsl 谓词根据另一个节点的值选择一个节点

转载 作者:数据小太阳 更新时间:2023-10-29 02:09:14 26 4
gpt4 key购买 nike

与此问题类似的问题: XPath: select a node based on another node?

该对象是根据同级节点的值选择节点 - 在本例中是根据 Pagetype 节点的值选择 Pagetitle 节点。

路径:

/dsQueryResponse/Rows/Row/@Title
/dsQueryResponse/Rows/Row/@Pagetype
/dsQueryResponse/Rows/Row/@Pagetitle

这个 xsl 没有返回任何东西:

<xsl:value-of select= "/dsQueryResponse/Rows/Row[Pagetype='Parent']/@Pagetitle" />  

示例 xml:

<dsQueryResponse>
<Rows>
<Row>
<Title>1</Title>
<Pagetype>Parent</Pagetype>
<Pagetitle>title of page</Pagetitle>
</Row>
</Rows>
</dsQueryResponse>

目标是如果 Pagetitle 的 Pagetype 值为“Parent”,则返回它们的值。

最佳答案

@ 符号表示节点的属性。所以如果要返回Pagetype属性等于Parent的属性Pagetitle的值,应该是:

<xsl:value-of select= "/dsQueryResponse/Rows/Row[@Pagetype='Parent']/@Pagetitle" />

我用来测试 XPATH 的有用资源是 http://www.xmlme.com/XpathTool.aspx

关于xml - 使用 xsl 谓词根据另一个节点的值选择一个节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7824724/

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