RE: [xsl] WG: Display attribute inside an xsl:for-each-group loop

Subject: RE: [xsl] WG: Display attribute inside an xsl:for-each-group loop
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 23 Jun 2005 08:36:39 +0100
> Line 4 is of special interest - thats where the contents should :) be
> displayed. While <xsl:value-of select="text()" /> works fine,
> <xsl:value-of select="@myattr/text()" /> produces an error in the
> XSL-parser:
>  
> Warning: on line 65 of
> file:/srv/www/htdocs/bka/./tmp/evaluations/42ba56a40e38d.xsl: 
> The child
> axis starting at an attribute() node will never select anything
>  

And I thought that error message was so helpful!

To display the value of attribute @att, do <xsl:value-of select="@att"/>.
The message is telling you that @att/text() doesn't make much sense: it's
short for attribute::att/child::text(), and attribute nodes don't have
children so this will always be an empty set.

(There are some object models in which attribute nodes do own text nodes;
but that's not the case in the XPath model).

To display the element, it's better to do <xsl:value-of select="."/> than
<xsl:value-of select="text()"/>. That's because an element may own several
text nodes, separated by comments or processing instructions. XSLT 2.0 will
give you the space-separated concatenation of the text nodes, but 1.0 will
give you the first one and ignore the others.

Michael Kay
http://www.saxonica.com/

Current Thread