aspose file tools*
The moose likes XML and Related Technologies and the fly likes How do you force a carriage return for text output? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How do you force a carriage return for text output?" Watch "How do you force a carriage return for text output?" New topic
Author

How do you force a carriage return for text output?

Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi,
This should be something simple but I can't insert CR or LF when using <xsl : output method="text">.
The output all runs together. If tried using
xA, xD, x86929, and ^M ... they all get displayed or ignored!
Anyone know how to do this??
Thanks
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited March 15, 2001).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Khun Yee Fung
Greenhorn

Joined: Feb 23, 2001
Posts: 24
Usually, you force some text to be output by using xsl:text. Care to include a snippet?

------------------
Khun Yee Fung
Author of XSLT: Working with XML and HTML


Khun Yee Fung<BR>Author of <A HREF="http://www.amazon.com/exec/obidos/ASIN/0201711036/ref=ase_electricporkchop/107-0402457-1632559" TARGET=_blank rel="nofollow">XSLT: Working with XML and HTML</A>
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Khun Yee,
Here's snippet


Can't see what I'm doing wrong
[The UBB keeps translating the xA and xD codes !]
[This message has been edited by Jane Griscti (edited March 15, 2001).]
Khun Yee Fung
Greenhorn

Joined: Feb 23, 2001
Posts: 24
Hmmm... you don't see the carriage return you have included by using xsl:text as well? Or you just don't see the linefeeds for using the entity &#xA; only? If you want to preserve the white spaces contained in an element, you can use the xml:space attribute (in this case, as an attribute of your xsl:value-of element). as well.
I used XT and Saxon to try something similar to the code you included here, and both gave me too many linefeeds...

------------------
Khun Yee Fung
Author of XSLT: Working with XML and HTML
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Thanks Khun Yee.
I guess I should have been more to the point . The code is an example from Beginning XML to demonstrate XPath axis. Here's the full source for the .xml file:

and for the .xsl file:

So, I'm not trying to output the contents of an elment; just it's name; I tried preserve-space but it doesn't work either; I guess because it relates only to the element content.
I'm using 'xt order.xml order.xsl' ... and displaying the result to the screen. Tried directing it to a file with the same result, no linefeeds/cr's.

------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited March 15, 2001).]
Khun Yee Fung
Greenhorn

Joined: Feb 23, 2001
Posts: 24
Ok. I got it. This is the XSLT document I have to output carriage returns you need.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="text" indent="yes"/>
<!-- start at the document root -->
<xsl:template match="/">
<!-- select any element that follows
the 'item' element and output it's name -->
<xsl:for-each select="/order/item/following::*">
<xsl:value-of select="name()"/><xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template match="text()"/>
<!-- appears to be redundant -->
</xsl:stylesheet>
The second template is redundant because you never allow XSLT to leave the template matching the root of the document. So it is redundant. In general, it is a dangerous template to be around, as it gets rid of all character data, if you are not careful.
So, do use xsl:text as is shown above.

------------------
Khun Yee Fung
Author of XSLT: Working with XML and HTML
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Thanks Khun Yee! Got it working
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
I played with &#x0D; &#x0A; in XML/XSLT and the result was confusing. When I put &#x0D; &#x0A; + something else in XSLT � they went into output; whilst (reading Beginning XML significally improved my vocabulary ) / without any extra symbols were ignored... This small article explaines a lot:
Whitespace preserving and stripping http://www.vbxml.com/xsl/examplewhitespace_stripping.asp

[This message has been edited by Mapraputa Is (edited March 17, 2001).]


Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How do you force a carriage return for text output?