469,352 Members | 1,697 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

Searching the newline charcter using XSLT

Hi,

I am fetching the data from the database and assigning it to the textarea. Before that Xml is loaded with data and then stylesheet gets applied to the xml to generate the html output with textarea with data in it. I want to replace the newline character with '\n' character. I tried to use following psedudo code

:
:
<xsl:when test="contains($text,' ')">
<xsl:value-of select="substring-before($text, ' ')"/>\n<xsl:call-template name="break">
<xsl:with-param name="text" select="substring-after($text,' ')"/>
</xsl:call-template>
</xsl:when>

This did not worked. I have also tried to use '&#xa' instead but that also did not worked.

Can anybody tell me how to search and replace the newline character using xslt?

Regards
Amol Lokhande
Dec 4 '08 #1
4 8171
Dormilich
8,652 Expert Mod 8TB
you could try
Expand|Select|Wrap|Line Numbers
  1. <xsl:text>&#10;</xsl:text>
since \n doesn't have any special meaning is xslt.
Dec 4 '08 #2
I think both should work

Expand|Select|Wrap|Line Numbers
  1.     <xsl:text>&#xD;</xsl:text>
  2.     <xsl:text>
  3. </xsl:text> 

---------------------------------------------
Sample XML FIle
---------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <root>
  3. <library id="1">
  4. <books>
  5. <book id="1">
  6.     <name>Book 1</name>
  7.     <author>Author A</author>
  8. </book>
  9. <book id="2">
  10.     <name>Book 2</name>
  11.     <author>Author B</author>
  12. </book>
  13. <book id="3">
  14.     <name>Book 3</name>
  15.     <author>Author C</author>
  16. </book>
  17. <book id="4">
  18.     <name>Book 4</name>
  19.     <author>Author A and Author D</author>
  20. </book>
  21. </books>
  22. </library>
  23. </root>
---------------------------------------------
Sample XSL FIle
---------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  3. <xsl:output method="text"/>
  4. <xsl:template match="/">
  5.     <xsl:text>&#xD;</xsl:text>
  6.     <xsl:apply-templates select="root/library[./@id = '1']/books/book"/>
  7. </xsl:template>
  8. <xsl:template match="book">
  9.     <xsl:value-of select="./@id"/>
  10.     <xsl:value-of select="' Title: '"/>
  11.     <xsl:value-of select="name"/>
  12.     <xsl:value-of select="' Author: '"/>
  13.     <xsl:value-of select="author"/>
  14.     <xsl:text>&#xD;</xsl:text>
  15.     <xsl:text>
  16. </xsl:text> 
  17. </xsl:template>
  18. </xsl:stylesheet>
---------------------------------------------
Output (notice two new lines appended after each row)
---------------------------------------------
1 Title: Book 1 Author: Author A


2 Title: Book 2 Author: Author B


3 Title: Book 3 Author: Author C


4 Title: Book 4 Author: Author A and Author D
Sep 28 '10 #3
in my post above the browser converted this code

<xsl:text> & # 1 0 ; </xsl:text>

(remove all spaces from abobve)

to

<xsl:text> </xsl:text>
Sep 28 '10 #4
jkmyoung
2,057 Expert 2GB
Could try:
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="newline">
  2. <xsl:text>
  3. </xsl:text>
  4. </xsl:variable>
What is processing the result of the transformation?
Sep 28 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by sal achhala | last post: by
2 posts views Thread by Harry Zoroc | last post: by
2 posts views Thread by jty202 | last post: by
29 posts views Thread by runningdog | last post: by
reply views Thread by Electric Co. | last post: by
1 post views Thread by Twinkle | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.