This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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).]
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>
Joined: Aug 30, 2000
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
Joined: Feb 23, 2001
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
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...
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
Joined: Feb 23, 2001
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.
I played with
in XML/XSLT and the result was confusing. When I put
+ 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).]