Whitespace stripping

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

Whitespace stripping

Ronald Bourret
Hello,

I am using SAXON 6.5.4. For some reason, SAXON is stripping whitespace
from a literal element in the stylesheet.

My input document is:

    <rpb_google_adsense />

My stylesheet is:

    <xsl:stylesheet version="1.0"
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" indent="no"
                omit-xml-declaration="yes" />

    <xsl:preserve-space elements="script" />

    <xsl:template match="rpb_google_adsense">
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    </xsl:template>

    </xsl:stylesheet>

The output document is:

    <script type="text/javascript"
       src="http://pagead2.googlesyndication.com/pagead/show_ads.js"/>

As you can see, the carriage return is stripped from the content of the
<script> element, which allows SAXON to write <script> out as an empty
element using the shorthand form. Does the xsl:preserve-space element
not apply to literal elements in the stylesheet?

(The real problem here is the Internet Explorer ignores the script
element when written as <script ... /> but not when written as <script
...></script>. Go figure.)

Thanks in advance,

-- Ron



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Whitespace stripping

Rob Koberg
Hi,

You will want/need to do:

<script ...>//</script>

or something like that.

best,
-Rob

Ronald Bourret wrote:

>    <xsl:template match="rpb_google_adsense">
>    <script type="text/javascript"
>      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
>    </script>
>    </xsl:template>
>


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Whitespace stripping

JBryant
In reply to this post by Ronald Bourret
Hi, Ron,

Just as a hack, you could try adding a comment instruction before closing
the script element, thus:

    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
      <xsl:comment>No shorthand!</xsl:comment>
    </script>

I _think_ that would force the script element to not collapse, but I've
not tested it - just an idea.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)




Ronald Bourret <[hidden email]>
Sent by: [hidden email]
09/16/2005 01:08 PM
Please respond to
[hidden email]


To
[hidden email]
cc

Subject
[saxon] Whitespace stripping






Hello,

I am using SAXON 6.5.4. For some reason, SAXON is stripping whitespace
from a literal element in the stylesheet.

My input document is:

    <rpb_google_adsense />

My stylesheet is:

    <xsl:stylesheet version="1.0"
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" indent="no"
                omit-xml-declaration="yes" />

    <xsl:preserve-space elements="script" />

    <xsl:template match="rpb_google_adsense">
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    </xsl:template>

    </xsl:stylesheet>

The output document is:

    <script type="text/javascript"
       src="http://pagead2.googlesyndication.com/pagead/show_ads.js"/>

As you can see, the carriage return is stripped from the content of the
<script> element, which allows SAXON to write <script> out as an empty
element using the shorthand form. Does the xsl:preserve-space element
not apply to literal elements in the stylesheet?

(The real problem here is the Internet Explorer ignores the script
element when written as <script ... /> but not when written as <script
...></script>. Go figure.)

Thanks in advance,

-- Ron



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server.
Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Whitespace stripping

Martin Honnen-2
In reply to this post by Ronald Bourret


Ronald Bourret wrote:


>    <xsl:output method="xml" indent="no"
>                omit-xml-declaration="yes" />
>
>    <xsl:preserve-space elements="script" />
>
>    <xsl:template match="rpb_google_adsense">
>    <script type="text/javascript"
>      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
>    </script>

>    <script type="text/javascript"
>       src="http://pagead2.googlesyndication.com/pagead/show_ads.js"/>


> As you can see, the carriage return is stripped from the content of the
> <script> element, which allows SAXON to write <script> out as an empty
> element using the shorthand form. Does the xsl:preserve-space element
> not apply to literal elements in the stylesheet?
>
> (The real problem here is the Internet Explorer ignores the script
> element when written as <script ... /> but not when written as <script
> ...></script>. Go figure.)

How about using output method="html" then if you want to send the markup
to an HTML parser?
<script /> is not proper HTML so that is not IE's fault that it has
problems with that markup.


--

        Martin Honnen
        http://JavaScript.FAQTs.com/


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Whitespace stripping

Michael Kay
In reply to this post by Ronald Bourret
xsl:preserve-space applies to whitespace in source documents, it doesn't
affect whitespace in the stylesheet. All whitespace text nodes are stripped
from the stylesheet unless

(a) they are part of <xsl:text>, or
(b) you specify xml:space=preserve

I suggest
<xsl:script>
 <xsl:text>&#xa;</xsl:text>
</xsl:script>

Better, use the HTML output method.

Michael Kay

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Ronald Bourret
> Sent: 16 September 2005 19:08
> To: [hidden email]
> Subject: [saxon] Whitespace stripping
>
> Hello,
>
> I am using SAXON 6.5.4. For some reason, SAXON is stripping
> whitespace
> from a literal element in the stylesheet.
>
> My input document is:
>
>     <rpb_google_adsense />
>
> My stylesheet is:
>
>     <xsl:stylesheet version="1.0"
>                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
>     <xsl:output method="xml" indent="no"
>                 omit-xml-declaration="yes" />
>
>     <xsl:preserve-space elements="script" />
>
>     <xsl:template match="rpb_google_adsense">
>     <script type="text/javascript"
>       src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
>     </script>
>     </xsl:template>
>
>     </xsl:stylesheet>
>
> The output document is:
>
>     <script type="text/javascript"
>        src="http://pagead2.googlesyndication.com/pagead/show_ads.js"/>
>
> As you can see, the carriage return is stripped from the
> content of the
> <script> element, which allows SAXON to write <script> out as
> an empty
> element using the shorthand form. Does the xsl:preserve-space element
> not apply to literal elements in the stylesheet?
>
> (The real problem here is the Internet Explorer ignores the script
> element when written as <script ... /> but not when written
> as <script
> ...></script>. Go figure.)
>
> Thanks in advance,
>
> -- Ron
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App
> Server. Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Whitespace stripping

Rob Koberg
Michael Kay wrote:

> xsl:preserve-space applies to whitespace in source documents, it doesn't
> affect whitespace in the stylesheet. All whitespace text nodes are stripped
> from the stylesheet unless
>
> (a) they are part of <xsl:text>, or
> (b) you specify xml:space=preserve
>
> I suggest
> <xsl:script>
>  <xsl:text>&#xa;</xsl:text>
> </xsl:script>


Just curious (cause you are almost always right :), why do you suggest
this over something simple like '//'? (I assume xsl:script was a mistake?)

>
> Better, use the HTML output method.
>
> Michael Kay
>


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Whitespace stripping

Michael Kay
>
> Just curious (cause you are almost always right :), why do
> you suggest
> this over something simple like '//'? (I assume xsl:script
> was a mistake?)

Because you (or someone) asked how to get a newline in there, and it's easy
to do, so it seemed simpler to answer the question as posed!

Michael Kay




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Whitespace stripping

Ronald Bourret
In reply to this post by Martin Honnen-2
Thanks to everyone for their suggestions. I used Michael's -- looks like
I didn't read the spec carefully enough to notice that whitespace was
preserved in xsl:text nodes.

As to the comment that <script /> is not proper HTML, could you clarify
that? I thought that XML was a proper subset of SGML and that HTML was
an SGML application, which would seem to imply that the <script />
shorthand would be legal HTML.

-- Ron

Martin Honnen wrote:

> <script /> is not proper HTML so that is not IE's fault that it has
> problems with that markup.




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Whitespace stripping

Michael Kay
HTML and XML are both subsets of SGML, but they are different (overlapping)
subsets. Not everything that's legal in XML is legal in HTML.

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

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Ronald Bourret
> Sent: 17 September 2005 06:07
> To: [hidden email]
> Subject: Re: [saxon] Whitespace stripping
>
> Thanks to everyone for their suggestions. I used Michael's --
> looks like
> I didn't read the spec carefully enough to notice that whitespace was
> preserved in xsl:text nodes.
>
> As to the comment that <script /> is not proper HTML, could
> you clarify
> that? I thought that XML was a proper subset of SGML and that
> HTML was
> an SGML application, which would seem to imply that the <script />
> shorthand would be legal HTML.
>
> -- Ron
>
> Martin Honnen wrote:
>
> > <script /> is not proper HTML so that is not IE's fault that it has
> > problems with that markup.
>
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App
> Server. Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Whitespace stripping

Martin Honnen-2
In reply to this post by Ronald Bourret


Ronald Bourret wrote:

 > Martin Honnen wrote:
 >
 >> <script /> is not proper HTML so that is not IE's fault that it has
 >> problems with that markup.


> As to the comment that <script /> is not proper HTML, could you clarify
> that? I thought that XML was a proper subset of SGML and that HTML was
> an SGML application, which would seem to imply that the <script />
> shorthand would be legal HTML.

The DTD for SGML applications determines whether start and/or end tag
for an element are optional or required.
The HTML 4.01 strict DTD <http://www.w3.org/TR/html4/sgml/dtd.html>
defines the script element as follows:

<!ELEMENT SCRIPT - - %Script;          -- script statements -->
<!ATTLIST SCRIPT
   charset     %Charset;      #IMPLIED  -- char encoding of linked
resource --
   type        %ContentType;  #REQUIRED -- content type of script
language --
   src         %URI;          #IMPLIED  -- URI for an external script --
   defer       (defer)        #IMPLIED  -- UA may defer execution of
script --
   >

Start tag: required, End tag: required


See also the explanation of SGML DTD syntax in
<http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.3.3> where it
explains that "Two hyphens that appear after the element name mean that
the start and end tags are mandatory."


If you still think the construct is valid HTML then author an HTML 4
document declaring an HTML 4.01 DTD, insert e.g.
   <script type="text/javascript" src="file.js" />
in the document and try an SGML validator e.g. http://validator.w3.org/ 
and it will give you an error with that construct.


--

        Martin Honnen
        http://JavaScript.FAQTs.com/


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help