Different output when xml:space attribute added to result

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Different output when xml:space attribute added to result

Andrew Welch
After an answer I gave on xsl-list I noticed an odd behaviour specific to Saxon:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
       <root>
        <xsl:attribute name="xml:space">preserve</xsl:attribute>
                        <element/>
                        <element/>
                        <element/>
       </root>
</xsl:template>
</xsl:stylesheet>

Produces:

<root xml:space="preserve"><element/><element/><element/></root>

Remove the xsl:attribute (or change the name to something else) and you get:

<root>
   <element/>
   <element/>
   <element/>
</root>

This is consistent between 6.5.4 and 8.6.1.  Should added xml:space to
the result have this effect?

cheers
andrew


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Different output when xml:space attribute added to result

David Carlisle

serialisation spec

5.1.3 XML Output Method: the indent Parameter

  Whitespace characters MUST NOT be inserted in a part of the result
  document that is controlled by an xml:space attribute with value
  preserve. (See [XML10] for more information about the xml:space
  attribute.)

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Different output when xml:space attribute added to result

Andrew Welch
> serialisation spec
>
> 5.1.3 XML Output Method: the indent Parameter
>
>   Whitespace characters MUST NOT be inserted in a part of the result
>   document that is controlled by an xml:space attribute with value
>   preserve. (See [XML10] for more information about the xml:space
>   attribute.)

Yes - but isn't adding "xml:space" to the result tree just like adding
any other attribute - only when the result gets parsed should it have
an effect.

<foo xml:space="preserve">

is different to

<foo>
  <xsl:attribute name="xml:space">preserve</xsl:attribute>

In the former the xml:space operates on the document itself, and makes
it through to the result, so it will have an effect there too.

In the latter I wouldn't expect it  to have any effect on the
document, only on the result when it gets re-parsed.

An odd one, this.


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Different output when xml:space attribute added to result

David Carlisle

  Yes - but isn't adding "xml:space" to the result tree just like adding
  any other attribute - only when the result gets parsed should it have
  an effect.

The serialisation spec takes the view that it shouldn't  mess with space
where space is significant. In XSLT1 the XML output had no knowledge,
but the HTML output uses knowledge of individual elements to allow or
disallow addition of white space for indentation. In XSLT2 the xml
serialisation has a similar feature, but using xml:space rather than
element names.

  <foo xml:space="preserve">

  is different to

  <foo>
    <xsl:attribute name="xml:space">preserve</xsl:attribute>

  In the former the xml:space operates on the document itself.

Yes if by "document"  you mean the stylesheet.

<xsl:attribute name="xml:space"> is "just an attribute" as far as the
result tree is concerned, but white space added (or not) by the
serialiser is never in the result tree.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Different output when xml:space attribute added to result

Andrew Welch
>   <foo xml:space="preserve">
>
>   is different to
>
>   <foo>
>     <xsl:attribute name="xml:space">preserve</xsl:attribute>
>
>   In the former the xml:space operates on the document itself.
>
> Yes if by "document"  you mean the stylesheet.
>
> <xsl:attribute name="xml:space"> is "just an attribute" as far as the
> result tree is concerned, but white space added (or not) by the
> serialiser is never in the result tree.

Ah, I see - as the serialiser operates on the result tree it doesn't
know how xml:space got there, only that it's there now.

It's another +1 for Saxon then as MSXML doesn't behave this way.


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Different output when xml:space attribute added to result

Michael Kay
In reply to this post by Andrew Welch
As David points out, the serializer isn't allowed to add whitespace in a
place where it would be deemed significant by an XML parser, and that
includes any part of the result document underneath an element with
xml:space="preserve".

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

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> andrew welch
> Sent: 01 December 2005 11:02
> To: [hidden email]
> Subject: Re: [saxon] Different output when xml:space
> attribute added to result
>
> > serialisation spec
> >
> > 5.1.3 XML Output Method: the indent Parameter
> >
> >   Whitespace characters MUST NOT be inserted in a part of the result
> >   document that is controlled by an xml:space attribute with value
> >   preserve. (See [XML10] for more information about the xml:space
> >   attribute.)
>
> Yes - but isn't adding "xml:space" to the result tree just like adding
> any other attribute - only when the result gets parsed should it have
> an effect.
>
> <foo xml:space="preserve">
>
> is different to
>
> <foo>
>   <xsl:attribute name="xml:space">preserve</xsl:attribute>
>
> In the former the xml:space operates on the document itself, and makes
> it through to the result, so it will have an effect there too.
>
> In the latter I wouldn't expect it  to have any effect on the
> document, only on the result when it gets re-parsed.
>
> An odd one, this.
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep
> through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  
> DOWNLOAD SPLUNK!
> <a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=ick">http://ads.osdn.com/?ad_idv37&alloc_id865&op=ick
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Different output when xml:space attribute added to result

Paul Vinkenoog
Hi all,

Michael Kay wrote:

> As David points out, the serializer isn't allowed to add whitespace
> in a place where it would be deemed significant by an XML parser,
> and that includes any part of the result document underneath an
> element with xml:space="preserve".

What I don't understand, then, is why it does delete whitespace.
Looking again at Andrew's template:

<xsl:template match="/">
       <root>
                <xsl:attribute name="xml:space">preserve</xsl:attribute>
                        <element/>
                        <element/>
                        <element/>
       </root>
</xsl:template>

I would expect this output:

<root xml:space="preserve">
                        <element/>
                        <element/>
                        <element/>
       </root>

And not:

<root xml:space="preserve"><element/><element/><element/></root>

Or was that whitespace already discarded by the parser when the
stylesheet was read?


Greetings,
Paul Vinkenoog


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Different output when xml:space attribute added to result

Trevor Nash
On Fri, 2 Dec 2005 Paul Vinkenoog wrote:

>What I don't understand, then, is why it does delete whitespace.
>Looking again at Andrew's template:
>
><xsl:template match="/">
>       <root>
>                <xsl:attribute name="xml:space">preserve</xsl:attribute>
>                        <element/>
>                        <element/>
>                        <element/>
>       </root>
></xsl:template>

But the XSLT processor also uses an XML parser, so it may see
(depending on things like strip-space settings in the stylesheet)

<root><xsl:attribute
name="xml:space">preserve</xsl:attribute><element/><element/><element/></root>

The space is gone before the serialiser sees it.

Try
<root xml:space="preserve">
        <xsl:attribute name="xml:space">preserve</xsl:attribute>

Trevor Nash
Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771363
email:     [hidden email]       web:       http://www.melvaig.co.uk


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Different output when xml:space attribute added to result

Michael Kay
In reply to this post by Paul Vinkenoog

>
> What I don't understand, then, is why it does delete whitespace.
> Looking again at Andrew's template:
...
> Or was that whitespace already discarded by the parser when the
> stylesheet was read?


Yes, it was. Whitespace-only text nodes in a stylesheet are ignored unless
(a) their parent is an xsl:text element, or (b) they have an ancestor
element specifying xml:space="preserve".

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




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Different output when xml:space attribute added to result

Andrew Welch
In reply to this post by Paul Vinkenoog
> > As David points out, the serializer isn't allowed to add whitespace
> > in a place where it would be deemed significant by an XML parser,
> > and that includes any part of the result document underneath an
> > element with xml:space="preserve".
>
> What I don't understand, then, is why it does delete whitespace.
> Looking again at Andrew's template:
>
> <xsl:template match="/">
>        <root>
>                 <xsl:attribute name="xml:space">preserve</xsl:attribute>
>                         <element/>
>                         <element/>
>                         <element/>
>        </root>
> </xsl:template>
>
> I would expect this output:
>
> <root xml:space="preserve">
>                         <element/>
>                         <element/>
>                         <element/>
>        </root>
>
> And not:
>
> <root xml:space="preserve"><element/><element/><element/></root>
>
> Or was that whitespace already discarded by the parser when the
> stylesheet was read?

All whitespace text nodes in the stylesheet get stripped as they are
usually there from the indentation of code, for example:

 <xsl:if test="">
     <xsl:if test="">

There is a whitespace text node between those two <xsl:if>'s - you
wouldn't want that making it into the result tree as it's just there
for readability.

Using xml:space="preserve" makes the whitespace text nodes significant
and so they aren't stripped - also there's xsl:preserve-space and
xsl:strip-space to control how whitespace gets handled for elements in
the input XML.


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Different output when xml:space attribute added to result

Florent Georges
andrew welch wrote:

> All whitespace text nodes in the stylesheet get stripped
> as they are usually there from the indentation of code,

  Unless with an @xml:space="preserve" ancestor, as you said, or for
the xsl:text elements.

--drkm



       

       
               
___________________________________________________________________________
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
Téléchargez cette version sur http://fr.messenger.yahoo.com


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help