[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
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: alan.painter@xxxxxxx Date: Sun, 6 Jul 2008 14:33:59 +0200 |
I tried what you suggested, David (C), modulo the remark from David (P). (As David (P) mentioned, you can't put '<' characters in the middle of a Xpath literal string, so I just removed part from your example.) That brings me to this example stylesheet: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" > <xsl:output indent="yes" encoding="UTF-8" method="xml" /> <xsl:template match="/" name="main" > <root rootAttribute="example"> <xsl:text> </xsl:text > <xsl:comment select="'Here is my comment.'" /> <xsl:text> </xsl:text> <property example1="example1" /> <property example2="example2" /> </root> </xsl:template> </xsl:stylesheet> With this result: <?xml version="1.0" encoding="UTF-8"?> <root rootAttribute="example"> <!--Here is my comment.--> <property example1="example1"/> <property example2="example2"/> </root> Which, in the end, has both the comment line and and property line at the wrong indentation level (should both be at same level as property with attribute example2). The following "works", or produces the correct output, but I contend that adding the extra text nodes isn't very readable, and manually counting spaces is not intellectually gratifying, not to mention fastdious and error-prone. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0" > <xsl:output indent="yes" encoding="UTF-8" method="xml" /> <xsl:template match="/" name="main" > <root rootAttribute="example"> <xsl:text>  	</xsl:text> <xsl:comment select="'Here is my comment.'" /> <xsl:text>  	</xsl:text> <property example1="example1" /> <property example2="example2" /> </root> </xsl:template> </xsl:stylesheet> I guess that I'm really expecting the simple case to work, where indentation comes out as a function of nested children without having to add extraneous text nodes. Thanks for the help -alan ----- Original Message ----- From: "M. David Peterson" [m.david@xxxxxxxxxxxxx] Sent: 06/07/2008 04:41 CST To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] How to get comments to indent on their own line in XML output? On Sun, 06 Jul 2008 04:08:51 -0600, David Carlisle <davidc@xxxxxxxxx> wrote: > <xsl:text> </xsl:text> > <xsl:comment select="'Here<xsl:text> </xsl:text>xu is my comment.'" > /> > <xsl:text> </xsl:text> I assume you meant: <xsl:text> </xsl:text> <xsl:comment>Here is my comment.</xsl:comment> <xsl:text> </xsl:text> Either that, or I missed the errata for both the XML and XSLT specs that allow embedding markup into attributes and the addition of the select attribute to xsl:comment, respectively. ;-) -- /M:D M. David Peterson Co-Founder & Chief Architect, 3rd&Urban, LLC Email: m.david@xxxxxxxxxxxxxxx | m.david@xxxxxx Mobile: (206) 999-0588 http://3rdandUrban.com | http://amp.fm | http://www.oreillynet.com/pub/au/2354 **************************************************************** Ce message a ete transmis par Internet. Son emetteur peut ne pas etre l'emetteur annonce. Son contenu et toute piece jointe peuvent ne pas etre exacts. This message originated from the Internet. Its originator may or may not be who they claim to be and information contained in the message and any attachments may or may not be accurate. 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] How to get comments to in, Michael Kay | Thread | Re: [xsl] How to get comments to in, David Carlisle |
Re: [xsl] How to get comments to in, M. David Peterson | Date | [xsl] Passing HTML elements to a Te, Mark Anderson |
Month |