我正在尝试使用 for-each 来选择和显示一组子节点,但我被卡住了!
XML
<cta>
<text>Call to action text</text>
<link>call to action link location</link>
<alt>call to action alt text</alt>
<target>_blank</target>
<style>button blueBut</style>
</cta>
<cta>
<text>Call to action 2</text>
<link>call to action 2 link</link>
<alt>call to action 2 alt text</alt>
<target>_blank</target>
<style>button blueBut</style>
</cta>
XSL
<div class="buttonPostLeft">
<xsl:for-each select="/Properties/Data/Datum[@ID='ID1']/DCR[@Type='Overview']/overview/cta/*">
<a>
<xsl:attribute name='class'>
<xsl:value-of select="/Properties/Data/Datum[@ID='ID1']/DCR[@Type='Overview']/overview/cta/style" />
</xsl:attribute>
<xsl:attribute name='href'>
<xsl:value-of select="/Properties/Data/Datum[@ID='ID1']/DCR[@Type='Overview']/overview/cta/link" />
</xsl:attribute>
<xsl:attribute name='title'>
<xsl:value-of select="/Properties/Data/Datum[@ID='ID1']/DCR[@Type='Overview']/overview/cta/alt" />
</xsl:attribute>
<xsl:value-of select="/Properties/Data/Datum[@ID='ID1']/DCR[@Type='Overview']/overview/cta/text"/>
</a>
</xsl:for-each>
</div>
我基本上希望锚标记为 XML 树中具有该组属性的每个 cta 组重复。所以在这个例子中,DIV 中有 2 个链接。希望这有一点意义!