[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Best way of preserving comments?

Subject: Re: Best way of preserving comments?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 03 Apr 2013 14:23:46 +0100
Re:  Best way of preserving comments?
On 03/04/2013 14:08, Wolfgang Laun wrote:
Using XSLT 2, this combination:

  <xsl:strip-space elements = "*" />
  <xsl:template match="element()|attribute()">... skip selected *|@* ... />
  <xsl:template match="text()|@_ix">
    <xsl:copy-of select="."/>
  <xsl:template match="comment()">
    <xsl:copy-of select="."/><xsl:text>

is the best I could do to preserve the original comment and element
layout, shown with beginning of input and output XML, below. Can this
be improved? Losing empty lines is tolerable, losing line breaks is
not so great.


Within the body of the document just copying comments is fine but before or after the document element white space nodes are not generated as the default XDM generation does not consider white space children of the root node to be significant (and of course there are no other text node children of the root node in a well formed document.

So what I do is have two templates

<xsl:template match="/comment()" priority="2">
   <xsl:copy-of select="."/><xsl:text>&#10;</xsl:text>

<xsl:template match="comment()"> <xsl:copy-of select="."/> <xsl:text>

Of course this doesn't preserve newlines around initial comments
it just adds a newline whether there was one there or not but it works OK in practice.

Sometimes I also have

<xsl:template match="/" priority="2">

as well to get a newline at the start


________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.