考虑这个递归XSLT模板:的xsl:for-each循环意外的结果在条件测试
<xsl:template name="SUBREPORT_FIELDS" >
<xsl:for-each select="current()/section/@name">
<xsl:choose>
<xsl:when test="current()/section/@name = $pSectionName">
<xsl:call-template name="FieldSezione"/>
<xsl:call-template name="FIELDS"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="SUBREPORT_FIELDS"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
而下面的XML输入文件:
<box name="box3">
<section name="sEmicrania">
<box name="box4">
<treecombobox name="tc"/>
<textmemo name ="tm"/>
</box>
<box name="box4">
<section name="sZona">
<box name="box5">
<label name="label1"/>
<textmemo name="tmZona"/>
</box>
</section>
</box>
</section>
</box>
变量$ pSectionName将作为其值“sEmicrania”或“sZona”;这些是两个“<节>”元素的属性“名称”的值。
当变量$ pSectionName的值为sEmicrania时,模板正确地将条件测试评估为true,但如果变量的值为“sZona”,则测试评估为false。
我希望测试在两种情况下均返回true。
请发表** **重复性的例子 - 请参见:[MCVE] –
我认为你需要改变'current()/ section/@ name = $ pSectionName'就是'section/@ name = $ pSectionName'。 'current()'与'.'不同,尽管在大多数地方它们的行为方式都是一样的 – Pawel
“传递变量”是什么意思?您的模板未设置为接受参数。 – Matthew