gpt4 book ai didi

xml - 如何在 xslt 中使用 xpath 作为变量?

转载 作者:行者123 更新时间:2023-12-04 12:48:46 25 4
gpt4 key购买 nike

例如,我有一个变量 $myVar 等于:

<ResultSet>
<Row>
<Cell name="NEXTVAL" type="NUMBER">475535</Cell>
</Row>
<Row>
<Cell name="NEXTVAL" type="NUMBER">475536</Cell>
</Row>
<Row>
<Cell name="NEXTVAL" type="NUMBER">475537</Cell>
</Row>
</ResultSet>

如何在 xslt 中为这个变量使用 xpath?

比如以某种方式在 /ResultSet/Row[1]/Cell 中获取值

最佳答案

如果你的变量是这样构成的

<xsl:variable name="myVar" as="element()">
<ResultSet>
<Row>
<Cell name="NEXTVAL" type="NUMBER">475535</Cell>
</Row>
<Row>
<Cell name="NEXTVAL" type="NUMBER">475536</Cell>
</Row>
<Row>
<Cell name="NEXTVAL" type="NUMBER">475537</Cell>
</Row>
</ResultSet>
</xsl:variable>

那么你的 xpath 应该是这样的

<xsl:sequence select="$myVar/Row[1]/Cell"/>

您的变量“站立”在 ResultSet 节点上,因此您不想使用 $myVar/ResultSet,因为在该级别上只有 Row 节点。请注意,您需要将变量设置为元素(“as”属性)。如果您的命名空间是相关的并且某些变量具有与其他变量不同的默认命名空间,您可以像这样为这个 xpath 表达式设置默认命名空间

<xsl:sequence select="$myVar/Row[1]/Cell" xpath-default-namespace="http://something.com"/>

您还可以为整个样式表设置默认命名空间。如果你想忽略命名空间,你可以像这样使用 xpath

<xsl:sequence select="$myVar/*:Row[1]/*:Cell"/>

关于xml - 如何在 xslt 中使用 xpath 作为变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14036897/

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