RE: [xsl] How to get comments to indent on their own line in XML output?

Subject: RE: [xsl] How to get comments to indent on their own line in XML output?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 4 Jul 2008 23:10:18 +0100
The serialization spec (for 2.0) says that when indenting, whitespace may be
added only immediately before an (element) start tag or immediately after an
end tag. This means it can't be inserted between a comment and a text node.
Although there's no such rule in XSLT 1.0, the logic is the same; it's
generally unsafe. For example:

<date-of-birth>1832-01<!--I think it's a 1 but it might be a
7-->-05</date-of-birth>

If you add whitespace around the comment, the document becomes invalid
against the schema.

One could do better in some cases, for example for a comment that
immediately follows an end tag (or is separated from it only by whitespace);
but in the end, you have to decide how much effort to put into fine-tuning
the algorithm.

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

> -----Original Message-----
> From: alan.painter@xxxxxxx [mailto:alan.painter@xxxxxxx]
> Sent: 04 July 2008 19:20
> To: xsl-list
> Subject: [xsl] How to get comments to indent on their own
> line in XML output?
>
>
>
>
> Hi,
>
> I'm producing some XML output with indented="yes" and the
> indenting works great excelpt for the comment nodes, which
> push the following elements to the end of the comment line.
>
> I would have expected a comment to occupy its own line
> starting at current indentation level, with the following
> element on next line at same indentation.
>
> I've tried a few naove attempts at adding text nodes with
> newlines after comments, but no dice.
>
> Any suggestions for this?
>
> Thanks
>
> -alan
>
>
> Ensemble adoptons des gestes responsables : N'imprimez ce
> mail que si necessaire.
>
> Les informations contenues dans ce message et les pieces
> jointes (ci-apres denomme le message) sont confidentielles et
> peuvent etre couvertes par le secret professionnel. Si vous
> n'etes pas le destinataire de ce message, il vous est
> interdit de le copier, de le faire suivre, de le divulguer ou
> d'en utiliser tout ou partie. Si vous avez recu ce message
> par erreur, nous vous remercions de le supprimer de votre
> systeme, ainsi que toutes ses copies, et d'en avertir
> immediatement HSBC France et ses filiales par message de
> retour. Il est impossible de garantir que les communications
> par messagerie electronique arrivent en temps utile, sont
> securisees ou denuees de toute erreur, alteration,
> falsification ou virus. En consequence, HSBC France et ses
> filiales declinent toute responsabilite du fait des erreurs,
> alterations, falsifications ou omissions qui pourraient en resulter.
>
> Consider the environment before printing this mail.
>
> The information contained in this e-mail is confidential. It
> may also be legally privileged. If you are not the addressee
> you may not copy, forward, disclose or use any part of it. If
> you have received this message by error, please delete it and
> all copies from your system and notify the sender immediately
> by return e-mail. E-mail communications cannot be guaranteed
> to be timely secure, error or virus-free. The sender does not
> accept liability for any errors or omissions which arise as a result.

Current Thread