xsl-list
[Top] [All Lists]

RE: can you select name() of attributes?

2004-07-27 03:08:24

I want something that selects all the names of the 
attributes. Is something 
like the following possible?
<xsl:variable name="Attr" select="$Doc/@*/name()"/> or
<xsl:variable name="Attr" select="$Doc/name(@*)"/>


The XPath type system doesn't allow sequences of strings, so you can't
assign a collection of names to a variable. (As DC pointed out, you can
iterate over this collection, though).

XPath 2.0 does allow sequences of strings. However the "/" operator only
works on sequences of nodes (a much-debated question). So you would write:

<xsl:variable name="attr" select="for $n in $Doc/@* return name($n)"/>

This then allows

if ($attr = 'abc')

to test if any of the names is equal to 'abc'.

Michael Kay