是否可以对属性使用该命令?我希望它能够在不知道属性名称的情况下运行。这是一个简单的(糟糕的)示例:
<candy hard="true" soft="false" stripes="true" solid="false">
在我的脑海中(这不起作用)它应该看起来像这样:
<xsl:for-each select="candy/@[@='true']">
有没有办法解决这个问题,可以在不知道属性名称的情况下运行属性,或者我是否需要编写要查看的每个属性?
编辑
这是我尝试从属性名称创建变量(其中 value='true')的示例
<xsl:for-each select="candy/@*[. = 'true']">
<xsl:attribute name="candytype">
<xsl:value-of select="name()"/>
</xsl:attribute>
<xsl:text> </xsl:text>
<xsl:for-each>
最佳答案
OP评论:
can I return each attribute name (not value) whose value='true'?
<xsl:for-each select="candy/@*[. = 'true']">
<xsl:value-of select="name()"/>
<xsl:text> </xsl:text>
<xsl:for-each>
在 XSLT 2.0 中,只需计算此 XPath (2.0) 表达式:
candy/@*[. = 'true']/concat(name(.), ' ')
关于xslt - 你可以使用<xsl :for-each> to go through attributes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11769674/