4

Is it possible to use the command on attributes? I want this to be able to run without knowing the attribute names. Here's a quick (terrible) example:

<candy hard="true" soft="false" stripes="true" solid="false">

In my head (this doesn't work) it should look something like this:

<xsl:for-each select="candy/@[@='true']">

Is there a way around this to run through attributes without knowing their name, or do I need to write each attribute being looked at?

Edit

Heres an example of me trying to create a variable out of the attribute name where 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>
4

2 回答 2

8

OP的评论:

我可以返回 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(.), ' ')
于 2012-08-02T03:30:41.000 回答
1

What you want is

<xsl:for-each select="candy/@*">
于 2012-08-02T01:06:28.323 回答