Subject: RE: Result still indented despite indent="no"
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 20 Feb 2005 14:26:19 -0000
|
> The XSLT 1.0 spec(URL -
> http://www.w3.org/TR/1999/REC-xslt-19991116) says
> (section 3.4 Whitespace Stripping)
>
> "After the tree for a source document or stylesheet
> document has been constructed, but before it is
> otherwise processed by XSLT, some text nodes *are*
> stripped.
>
> A text node *is preserved if any of the following
> apply*:
>
> 1) The element name of the parent of the text node is
> in the set of whitespace-preserving element names.
>
> 2) The text node contains at least one non-whitespace
> character. As in XML, a whitespace character is #x20,
> #x9, #xD or #xA.
>
> 3) An ancestor element of the text node has an
> xml:space attribute with a value of preserve, and no
> closer ancestor element has xml:space with a value of
> default.
>
> Otherwise, the text node *is* stripped. "
>
> There seems no ambiguity, that in this example
> (provided by Dare Obasanjo) - white spaces *must* be
> stripped (as none of the above 3 conditions in spec
> are holding true).
Wrong. The first condition is true. The condition for an element name in a
source document to be a member of the set of whitespace-preserving element
names is defined in Erratum E30:
"For source documents, the set of whitespace-preserving element names is
specified by xsl:strip-space and xsl:preserve-space top-level elements.
Whether an element name is included in the set of whitespace-preserving
names is determined by the best match amongst xsl:strip-space or
xsl:preserve-space elements: it is included if and only if there is no match
or the best match is an xsl:preserve-space element."
In other words, if the stylesheet doesn't specify xsl:strip-space for an
element, then its whitespace text nodes must be preserved.
(You get the same answer from reading the original spec without the erratum;
the purpose of the erratum is to clarify what happens if there are
conflicting strip-space and preserve-space declarations.)
Michael Kay
http://www.saxonica.com/
>
> It seems to me, MSXML4 is compliant in this regard. I
> fear, Saxon and Xalan are not compliant..
>
> Also, I feel what the spec recommends in this
> regard(white space stripping) is correct..
> Unless the user explicitly gives instruction to
> preserve white spaces, they should be stripped. *White
> space only, text nodes* are of no use for application.
>
>
> Regards,
> Mukul
>
> --- "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
> wrote:
>
> > At 2005-02-19 19:02 -0800, Sebastien Boisvert wrote:
> > >I'm getting a result after applying a stylesheet
> > where
> > >some nodes get indented for some reason, even if I
> > set
> > >indent="no" and even the source document is not
> > >indented.
> > >
> > >It seems that calling a certain template when
> > >processing the root node somehow sets the indent
> > mode
> > >to 'yes' but only for that one template, as running
> > >the default template (ie <xsl:apply-templates />)
> > does
> > >not produce this problem...
> >
> > Good sleuthing there... well done ... that points to
> > interpretation of the
> > stylesheet into a node tree.
> >
> > >I've tried this on another processor with the exact
> > >same stylesheet and source code and it works as
> > >expected (indents do not happen).
> >
> > Ahhh .. that points to a bug ... unless of course
> > you used the MSXSL
> > processor for your alternate test in which it isn't
> > at all definitive
> > because the Microsoft processor throws away
> > whitespace-only text nodes
> > contrary to the explicit specification rules[1]. If
> > you used a processor
> > conformant in the area of whitespace handling, then
> > the test is more
> > meaningful.
> >
> > >Is there something/someway that I might be calling
> > the
> > >template that would cause it to produce indents in
> > >libxslt?
> >
> > Do you have xml:space="preserve" used anywhere?
> > That overrides the rules
> > regarding ignoring whitespace-only text nodes from
> > the stylesheet node tree
> > when building the result tree and would make any
> > such annotated nodes visible.
> >
> > I hope this helps.
> >
> > ...................... Ken
> >
> >
> > [1] - excerpts from an online debate regarding this
> > issue of handling
> > whitespace-only text nodes, July 2003:
> >
> > Microsoft's question:
> >
> >
> >
> http://lists.xml.org/archives/xml-dev/200307/msg00868.html
> >
> > Microsoft's answer (by another employee):
> >
> >
> >
> http://lists.xml.org/archives/xml-dev/200307/msg00872.html
> >
> > My claim where I observe Microsoft's non-compliance:
> >
> >
> >
> http://lists.xml.org/archives/xml-dev/200307/msg00870.html
> >
> > Microsoft's counter-claim:
> >
> >
> >
> http://lists.xml.org/archives/xml-dev/200307/msg00873.html
> >
> > My response:
> >
> >
> >
> http://lists.xml.org/archives/xml-dev/200307/msg00880.html
> >
> > Microsoft's position at the end of the debate:
> >
> >
> >
> http://lists.xml.org/archives/xml-dev/200307/msg00885.html
> >
> > I haven't heard anything official since, but as far
> > as I know, this
> > whitespace-handling behaviour has not changed.
> >
> >
> > --
> > 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 Breast Cancer Awareness
> > http://www.CraneSoftwrights.com/s/bc
> > Legal business disclaimers:
> > http://www.CraneSoftwrights.com/legal
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Read only the mail you want - Yahoo! Mail SpamGuard.
> http://promotions.yahoo.com/new_mail
|