[xsl] xsl:for-each and xml:space with text-nodes inbetween

Subject: [xsl] xsl:for-each and xml:space with text-nodes inbetween
From: "Buchcik, Kasimier" <k.buchcik@xxxxxxxxxxxx>
Date: Tue, 25 Apr 2006 21:45:30 +0200
Hi,

Does someone know what an XSLT 1.0 processor is expected
to do if the immediate child-node of an xsl:for-each is
a whitespace-only text node, which is preserved by xml:space?
Should any text-node, regardless if it's whitespace-only or not,
be reported as invalid at such a position?

Example

Stylesheet:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:template match="/">
		<foo>
		<!-- There's whitespace between xsl:for-each and
xsl:sort. -->
		<xsl:for-each select="/foo/bar" xml:space="preserve">
<xsl:sort /><xsl:value-of select="."/></xsl:for-each>
		</foo>
	</xsl:template>
</xsl:stylesheet>

Input:
<?xml version="1.0"?>
<foo>
  <bar>b</bar>
  <bar>c</bar>
  <bar>a</bar>
</foo>

Using the MSXML .NET Processor, I get the following result:

<?xml version='1.0' encoding='utf-8' ?>
<foo> a b c</foo>

If I change the whitespace-only text-node to contain a letter:
...
<xsl:for-each select="/foo/bar" xml:space="preserve">X<xsl:sort
/><xsl:value-of select="."/></xsl:for-each>
...
then an error is reported concerning the invalid position of xsl:sort
inside xsl:for-each. I'm confused here.

Was this maybe clarified in the XSLT 2.0 spec?

Regards,

Kasimier

Current Thread