Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] XSLT2.0 compatibility

From: "Houghton,Andrew" <houghtoa@-------->
To:
Date: 9/5/2006 6:00:00 PM
> 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:element>
  <xsl:value-of select="concat($newline,$newline,$indent)"/>
</xsl:element>

Should produce:

  <foo>

    <bar>
    </bar>

  </foo>

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


Andy.


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent