How to select each child node of a parent in a for-each xslt statement?

前端 未结 1 1334
没有蜡笔的小新
没有蜡笔的小新 2021-02-06 07:07

I want to select all child nodes from the adviceRow element (see xml data hereunder) in a for each loop.

I want to avoid having to write an xslt file like this:

<
相关标签:
1条回答
  • 2021-02-06 07:15

    Yes, you can nest for-each loops.

    Try this

    <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>
    

    The xpath "." refers to the current node (a.k.a the “context node”), "/*" select all the child nodes of the context node.

    0 讨论(0)
提交回复
热议问题