xslt - 你可以使用<xsl :for-each> to go through attributes?

标签 xslt foreach xslt-2.0

是否可以对属性使用该命令?我希望它能够在不知道属性名称的情况下运行。这是一个简单的(糟糕的)示例:

<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/

相关文章:

javascript - xsltprocessor 在 Chrome 中调试

php - 如何在不显式编写循环运算符的情况下展平一个简单的数组?

java - 使用 Saxon 时未拾取 XSLT 输入参数?

java - 使用 XSLT 将 XML 转换为 HTML

c# - 通过在 xslt 中调用 C# 函数来更改 xml 文件

javascript - 在 html 中显示来自 foreach 循环的 5 个结果

php - 如何去除特殊字符?

xml - XSLT - 识别具有相同属性值模式的连续节点

datetime - 如何使用 XSLT 将刻度转换为可读的日期时间?

html - 在 Internet Explorer 中使用 XSLT 和 CSS 处理 XML