Subject: Re: [xsl] plain text output From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx> Date: Wed, 17 Jul 2002 18:15:13 -0400 |
[Guy McArthur] > > What I've read so far for plain text output is unsatisfying. I have two > issues. > > 1. Preventing initial first lines. > > This template will print a blank first line. > > <xsl:template> > PDS_VERSION_ID = PDS3 > RECORD_TYPE = FIXED_LENGTH > </xsl:template> > When all else fails, the minimally intrusive thing I know to do is this - <xsl:template >PDS_VERSION_ID = PDS3 RECORD_TYPE = FIXED_LENGTH </xsl:template> > > 2. Inserting a carriage return. > > Simarly, putting in a bunch of > <xsl:text> </xsl:text> > elements disrupts the stylesheet. > > Is there any easier way to do it? > The reason this (and your earlier <xsl:text/> method) work is not the use of the xsl:text element per se, but rather the fact that there are two tags in a row with only whitespace between them. The processor has to decide if that white space is part of real character data or is just there for visual formatting and can therefore be ignored. The standard thing for the processor to do is to ignore such whitespace-only nodes. Therefore, in example 1, any element will do, and if you are using the text output method, you could use <a/> instead of <xsl:text/>. Your text starts after the <a/> element, and there is no line feed there. The line feed between the <xsl:template> and the <a/> is ignored, and you get what you want. As for new lines, they will be copied to the output as long as they are part of a chunk of character data. If you want them between, for example, two consecutive xsl:value-of elements, similar considerations apply. Whitespace between elements gets ignored. <xsl:text> is one way to put non-whitespace text there. A shorter way is to put a non-breaking space in place, like this: <xsl:value-of select='"xxx"'/>  <xsl:value-of select='"yyy"'/> Now the two xsl:value-of elements are not separated by whitespace, and so the new line is honored. In a decent editor or other viewer, the non-break ing space will display properly, but if the viewer expects one encoding and your output is in another, it may display as a strange character. But it is easier than <xsl:text> </xsl:text>. Any character will do, like a dash or period, but you do not always want something visible. You can also try to define an entity to use instead of the non-breaking space, like putting this into your stylesheet: <!DOCTYPE xsl:stylesheet[ <!ENTITY CR "<xsl:text> </xsl:text>"> ]> <xsl:value-of select='"xxx"'/>&CR; <xsl:value-of select='"yyy"'/> This works with Saxon, XT, Xalan, and Sablotron, but I can never get it to work with msxml, which complains about missing namespaces when I run it it XML Cooktop. Cheers, Tom P XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] plain text output, Guy McArthur | Thread | RE: [xsl] plain text output, Michael Kay |
Re: [xsl] Schema and fixed attribut, Jeni Tennison | Date | Re: [xsl] need a hint on matching t, J.Pietschmann |
Month |