XML 中的前同级
我有这样的 XML 数据:
<items>
<data>2</data>
<listElement>
<amounts>
<period_id>1</period_id>
<amount>5</amount>
</amounts>
<amounts>
<period_id>2</period_id>
<amount>6</amount>
</amounts>
<amounts>
<period_id>3</period_id>
<amount>7</amount>
</amounts>
<amounts>
<period_id>8</period_id>
<amount>89</amount>
</amounts>
</listElement>
</items>
<items>
<data></data>
<listElement>
<amounts>
<period_id>4</period_id>
<amount>55</amount>
</amounts>
<amounts>
<period_id>5</period_id>
<amount>9</amount>
</amounts>
<amounts>
<period_id>6</period_id>
<amount>20</amount>
</amounts>
<amounts>
<period_id>7</period_id>
<amount>80</amount>
</amounts>
</listElement>
</items>
在我的 xsl 代码中,我位于节点金额内,我想获取标签“数据”的值,谁是该标签金额的父级?
我正在使用 xalan 与 xslt1.0 和 apache fop
注意:我尝试过:
<xsl:value-of select="preceding-sibling::*data[normalize-space(.)]">
</xsl:value-of>
但仍然错误。
I have a XML data like that:
<items>
<data>2</data>
<listElement>
<amounts>
<period_id>1</period_id>
<amount>5</amount>
</amounts>
<amounts>
<period_id>2</period_id>
<amount>6</amount>
</amounts>
<amounts>
<period_id>3</period_id>
<amount>7</amount>
</amounts>
<amounts>
<period_id>8</period_id>
<amount>89</amount>
</amounts>
</listElement>
</items>
<items>
<data></data>
<listElement>
<amounts>
<period_id>4</period_id>
<amount>55</amount>
</amounts>
<amounts>
<period_id>5</period_id>
<amount>9</amount>
</amounts>
<amounts>
<period_id>6</period_id>
<amount>20</amount>
</amounts>
<amounts>
<period_id>7</period_id>
<amount>80</amount>
</amounts>
</listElement>
</items>
In my xsl code I'm inside a node amounts and I want to get the value of the tag "data" who is parent of this tag amounts?
I'm using xalan with xslt1.0 and apache fop
Note: I tried with:
<xsl:value-of select="preceding-sibling::*data[normalize-space(.)]">
</xsl:value-of>
But still wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,示例中的
data
元素是items
(amount
祖父)的子元素。使用这个:
也可以这样:
但是必须保证每个
items
中都有一个data
。如果您确实想使用
preceding-sibling
轴,那么:Do note that
data
element is a child ofitems
(amount
grandparent) in your sample.Use this:
Also this:
But it must be guaranteed that there is going to be one
data
in everyitems
.If you really want to use
preceding-sibling
axis then:从
amounts
元素的上下文:以下样式表将前面的
data
元素复制到每个amounts
元素中,使文档的其余部分保持不变:当应用于源文档时,它会产生以下输出:
From the context of an
amounts
element:The following stylesheet copies the preceding
data
element into eachamounts
element, leaving the rest of the document unchanged:It produces the following output when applied to your source document: