• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do you force a carriage return for text output?

 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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">
<xsl:output 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
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Khun Yee! Got it working
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic