关于 xslt 的新手问题。我有多个 xsl:if 检查,例如
<xsl:if test="node/node1"> ...</xsl:if>
...
<xsl:if test="node/node1"> ...</xsl:if>
...
<xsl:if test="node/node1"> ... </xsl:if>
有没有办法参数化测试条件,使代码更具可读性和易于维护?也许有一个变量或类似的东西
<xsl:variable name="node1Present" select="true()"/>
<xsl:if test="$node1Present"> ... </xsl:if>
我不明白如何构造变量来反射(reflect)“测试节点存在”(test="node/node1")
最佳答案
<xsl:variable name="node1Present" select="boolean(node/node1)"/>
对于节点集,当且仅当节点集不为空时,boolean()
才会转换为 true。
关于xslt - xsl - 多个 xsl :if with the same condition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3022068/