Re: [xsl] why no indent here

Subject: Re: [xsl] why no indent here
From: "Tony Graham" <tgraham@xxxxxxxxxx>
Date: Sun, 11 Dec 2011 21:36:51 -0000 (GMT)
On Sun, December 11, 2011 8:18 pm, Roelof Wobben wrote:
...
> But I get as output this :
>
> <!DOCTYPE head PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";><head>
>  <title>http://test.tamarawobben.nl</title>
> </head>
>
> instead of this :
>
> <!DOCTYPE head PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
>
> <head>
>  <title>http://test.tamarawobben.nl</title>
> </head>

Whitespace-only text nodes in the stylesheet are stripped by default. 
>From http://www.w3.org/TR/xslt#strip:

   For stylesheets, the set of whitespace-preserving element
   names consists of just xsl:text.

So if you were expecting whitespace-only text nodes from your stylesheet
to be reflected in your result, you need to wrap them in xsl:text
elements.

All that XSLT 1.0 says about '<xsl:output indent="yes" />' is:

   indent specifies whether the XSLT processor may add
   additional whitespace when outputting the result tree;
   the value must be yes or no [1]

so you're not even guaranteed to get an indented result even when you use
'indent="yes"' (but it practice it is universally supported AFAICT).

The specification for outputting the DOCTYPE declaration in XML output is:

   If the doctype-system attribute is specified, the xml
   output method should output a document type declaration
   immediately before the first element.

which is what you got, since the start-tag of the first element
immediately follows the DOCTYPE declaration.  You could try:

<xsl:template match="/">
    <xsl:text>&#10;</xsl:text>
    <xsl:apply-templates select="data/params" />
</xsl:template>

but it would be possible for the XSLT 1.0 processor to follow the letter
of the spec and omit the line break added from content of the xsl:text, so
YMMV.

Regards,


Tony Graham                                   tgraham@xxxxxxxxxx
Consultant                                 http://www.mentea.net
Mentea       13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
 --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
    XML, XSL-FO and XSLT consulting, training and programming

[1] http://www.w3.org/TR/xslt#output

Current Thread