Is there a way to walk-through a key and output all the values it contains?
<xsl:key name="kElement" match="Element/Element[@idref]" use="@idref" />
I though of it this way:
<xsl:for-each select="key('kElement', '.')">
<li><xsl:value-of select="." /></li>
</xsl:for-each>
However, this does not work. I simply want to list all the values in a key for testing purposes.
The question is simply: how can this be done?
You can’t. That’s not what keys are for.
You can loop through every element in a key using a single call to
key()if and only if the key of each element is the same.If you need to loop over everything the key is defined over, you can use the expression in the
match="..."attribute of your<key>element.So if you had a file like this:
And a key defined like this:
You can loop through what the key uses by using the contents of its
matchattribute:Alternatively, if each element had something in common:
Then you could define your key like this:
And iterate over all elements like this:
Because each element shares the value “survivor” for the
classattribute.In your case, your key is
So you can loop through everything it has like this: