473,804 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching the newline charcter using XSLT

33 New Member
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="substri ng-before($text, ' ')"/>\n<xsl:call-template name="break">
<xsl:with-param name="text" select="substri ng-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 8625
Dormilich
8,658 Recognized Expert Moderator Expert
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 Recognized Expert Top Contributor
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
1942
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 process is automated) from different websites thus the element names for author may differ! Is their a way of dealing with this, such as perhaps a standard adopted by, say educational websites to agree on element names ? Thanks very much
2
2334
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
17418
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 append together. please help. thanks!!
7
17301
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 XSL transform prior to validation is removing all the newlines. The XSL is simply adding a namespace: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
3
2095
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
1731
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
3483
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
1330
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 indent and newline formatting intact. ie. Console Code: XPathDocument myXPathDocument = new XPathDocument
1
2573
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 Beacz i am new in .NET. Plz help me twinkle
0
10320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10308
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10073
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9134
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7609
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5513
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.