RE: [xsl] XSLT2.0 compatibility

Subject: RE: [xsl] XSLT2.0 compatibility
From: "Houghton,Andrew" <houghtoa@xxxxxxxx>
Date: Tue, 5 Sep 2006 13:59:44 -0400
> From: Mukul Gandhi [mailto:gandhi.mukul@xxxxxxxxx]
> Sent: 05 September, 2006 13:31
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] XSLT2.0 compatibility
> On 9/5/06, Lin, Jessica <jlin@xxxxxxxxxxx> wrote:
> > How should I preserve the space of the xml for human
> reading? I found
> > indent="yes" is not good enough. I have to run prttey-print
> command in
> > xml spy edit environment to see a good indent xml file.
> I have found Saxon 8.x.x's implementation of indent="yes" to
> be quite good.

In general it is quite good, but it doesn't give you control
over formatting.  For example, it outputs 3 spaces as an
indent.  What if I thought 2 spaces were adequate?  I cannot
control it.  What if I wanted double newlines after certain
elements?  The list goes on, but this isn't Saxon's fault.
The XSLT specification doesn't provide for this level of
control throught the use of the indent="yes" attribute.

However, that doesn't mean that you cannot control indenting
yourself.  It is a pain in the neck, but it can be done.  Use
indent="no" and output the appropriate whitespace whereever
you want it.

<xsl:variable name="indent"  select="string('&#20;&#20;')"/>
<xsl:variable name="newline" select="string('&#10;')"/>

<xsl:value-of select="concat($newline,$indent)"/>
<xsl:element name="foo">
  <xsl:value-of select="concat($newline,$newline,$indent,$indent)"/>
  <xsl:element name="bar">
    <xsl:value-of select="concat($newline,$indent,$indent)"/>
  <xsl:value-of select="concat($newline,$newline,$indent)"/>

Should produce:




Ugly, especially for deeply nested structure, but it works.


Current Thread