如何在 for-each xslt 语句中选择父节点的每个子节点? [英] How to select each child node of a parent in a for-each xslt statement?
本文介绍了如何在 for-each xslt 语句中选择父节点的每个子节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从每个循环中的adviceRow 元素(参见下面的xml 数据)中选择所有子节点.
I want to select all child nodes from the adviceRow element (see xml data hereunder) in a for each loop.
我想避免编写这样的 xslt 文件:
I want to avoid having to write an xslt file like this:
<xsl:for-each select="Tables/routeAdviceTable/routeAdviceRows/adviceRow">
<xsl:value-of select="cog" />
<xsl:value-of select="current" />
<xsl:value-of select="distance" />
<xsl:value-of select="dtg" />
etc..
</xsl:for-each>
因为一行可以有很多单元格(我有很多相似但内容不同的表格)
Because a row can have many cells (and i have lots of similar but contentwise different tables)
我可以使用嵌套的 for-each 循环吗?类似的东西:
Can I work with a nested for-each loop? Something like:
for-each advice row:
for-each child of advicerow?
<Tables>
<routeAdviceTable>
<routeAdviceRows>
<adviceRow>
<cog>313</cog>
<current>0.3</current>
<distance>58.8</distance>
<dtg>1374786000000</dtg>
<latitude>????</latitude>
<longitude>????</longitude>
<pressure>22.300001</pressure>
<sea>0.2</sea>
<sog>14.7</sog>
<stw>???</stw>
<swell>1.7</swell>
<waves>1.711724324567694</waves>
<wind>0.8</wind>
</adviceRow>
</routeAdviceRows>
</routeAdviceTable>
谢谢
推荐答案
是的,您可以嵌套 for-each 循环.
Yes, you can nest for-each loops.
试试这个
<xsl:for-each select="Tables/routeAdviceTable/routeAdviceRows/adviceRow">
<xsl:for-each select="./*">
<!--
Your code i.e.
<td class="{name(.)}">
<xsl:value-of select="."></xsl:value-of>
</td>
-->
</xsl:for-each>
</xsl:for-each>
xpath."指的是当前节点(又名上下文节点"),/*"选择上下文节点的所有子节点.
The xpath "." refers to the current node (a.k.a the "context node"), "/*" select all the child nodes of the context node.
这篇关于如何在 for-each xslt 语句中选择父节点的每个子节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文