473,320 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 8569
Dormilich
8,658 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

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

Similar topics

3
by: sal achhala | last post by:
I'm working with java and XML documents in order to search for keywords in a given element name, eg element name 'author' == "jo blogs". The problem is the XML documents are downloaded (this...
2
by: Harry Zoroc | last post by:
Is there something like a XSLT compiler or XSLT obfuscator available? If yes, does this compiiler/obfuscator handle XSLT 2.0, XPATH 2.0 and XQUERY statements as well or only XSLT 1.0 ? Harry
2
by: Matt | last post by:
I want to generate text output from XML using XSLT. The question is how to produce a newline? When I produce HTML as output, I have no problems. But when I attempt to produce text, all data is...
7
by: jjouett | last post by:
I'm trying to preserve the newline characters in my transformed XML (read from a file) to provide a meaningful line number when validation errors occur. However, my current method which performs an...
3
by: Paul H | last post by:
I have a text file that contains the following: ******************** __StartCustomerID_41 Name: Fred Smith Address: 57 Pew Road Croydon
2
by: jty202 | last post by:
I use a the function Instr() in VB6 to search for a search-string in String var. It returns the position of the found search-string. Is there such a funtion in ASP.net?
29
by: runningdog | last post by:
Hi, I would like to be able to embed a newline in a text string. Is there any convienent notation to do this TIA Steve
0
by: Electric Co. | last post by:
Hello, I am trying to write a small xslt utility to build and quickly check my transforms. Unfortunately, I can not figure out how have the output from the transform written to the console with...
1
by: Twinkle | last post by:
HI Guys I have a prob i want to search a text(Like Charcter search,name search as searching criteria) in PDF file by the "AVDOC" Object. in .NET. can u give an idea how to start this Application...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.