【发布时间】:2012-11-28 13:44:08
【问题描述】:
我有以下 xml
<root>
<element id='1'>blah</element>
<element id='2'>blah</element>
<element id='3'>blah</element>
</root>
传入我的 xsl 的参数是..
<Ids>
<id>1</id>
<id>2</id>
<id>3</id>
</Ids>
在我的 xsl 中,我想遍历 parm 和 xml 以匹配具有等于 parm id 值之一的 id 属性的任何元素。这是动态的,我不知道它们的值将是 uuid。
我已经尝试过了,但我找不到元素 id
<xsl:for-each select="/$Ids/id">
<xsl:variable name="driverId" select="."/>
<xsl:for-each select="/root/element[@id=$driverId]">
//do something
</xsl:for-each>
</xsl:for-each>
如果在第一个 for each 之前将元素 id 的值发送出去,我可以看到所有值,但在循环中看不到。这是否可能以我正在考虑的方式进行。
还是不行,我改成
结果相同。
如果我把 for-each 放在参数之外,则在 xsl 中
<test><xsl:for-each select="/root/element/@id"></test>
我明白了
<test>1 2 3</test>
如果放
<test><xsl:for-each select="/root/element/@id"></test>
里面
<xsl:for-each select="$Ids/id">
我什么也没得到???
【问题讨论】:
标签: xml xslt xml-parsing xslt-1.0 xslt-2.0