[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:for-each and xml:space with text-nodes inbetwe

Subject: Re: xsl:for-each and xml:space with text-nodes inbetween
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 25 Apr 2006 16:44:01 -0400
xsl for each xml space
At 2006-04-25 21:45 +0200, Buchcik, Kasimier wrote:
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?

Section 8 clearly states that the content is xsl:sort followed by the template:


<!-- Category: instruction -->
<xsl:for-each
  select = node-set-expression>
  <!-- Content: (xsl:sort*, template) -->
</xsl:for-each>

Should any text-node, regardless if it's whitespace-only or not,
be reported as invalid at such a position?

Yes, it is an error, and Saxon reports it as an error, because the xml:space="preserve" creates a node of the template before the xsl:sort instruction, which is not allowed.


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

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

I would assess that as a bug ... the space character is clearly part of the template and the standard does not allow any part of the template before xsl:sort.


then an error is reported concerning the invalid position of xsl:sort
inside xsl:for-each. I'm confused here.

I think you are confused because of the bug.


I believe Saxon implements this correctly.

Was this maybe clarified in the XSLT 2.0 spec?

Not applicable. XSLT 1 is, I belive, quite clear. Using xml:space="preserve" in a stylesheet is a syntactic mechanism to keep from having to use <xsl:text> for white-space-only nodes ... I use it for that myself. By using it you have, in effect, wrapped the first white-space-only text node in <xsl:text>, which also would not be allowed to be before <xsl:sort/>.


I hope this helps.

. . . . . . . . Ken

T:\ftemp>type kasimier.xml
<?xml version="1.0"?>
<foo>
  <bar>b</bar>
  <bar>c</bar>
  <bar>a</bar>
</foo>

T:\ftemp>type kasimier.xsl
<?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>

T:\ftemp>xslt kasimier.xml kasimier.xsl con
Error at xsl:for-each on line 8 of file:/T:/ftemp/kasimier.xsl:
  An xsl:sort element is not allowed here
Transformation failed: Failed to compile stylesheet. 1 error detected.

T:\ftemp>

--
Registration open for XSLT/XSL-FO training: Wash.,DC 2006-06-12/16
Also for XSLT/XSL-FO training:    Minneapolis, MN 2006-07-31/08-04
Also for XML/XSLT/XSL-FO training:Birmingham,England 2006-05-22/25
Also for XSLT/XSL-FO training:    Copenhagen,Denmark 2006-05-08/11
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.