[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Replacing character entities

Subject: Re: Replacing character entities
From: "Wagstaff, Jason" <WagstaffJ@xxxxxxxxxxxx>
Date: Tue, 15 Feb 2005 10:22:12 -0600
xsl escape character
Thanks. This works, except for with character entities. Perhaps I am
missing something on how to escape character entities, but, when I run
this:
 

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">

<div>

<xsl:call-template name="par"/>

</div>

</xsl:template>

<xsl:template name="par">

<xsl:param name="text" select="big/block"/>

<p>

<xsl:value-of select="substring-before(concat($text,'&#13;'),'&#13;')"/>

</p>

<xsl:if test="contains($text,'&#13;')">

<xsl:call-template name="par">

<xsl:with-param name="text">

<xsl:value-of select="substring-after($text,'&#13;')"/>

</xsl:with-param>

</xsl:call-template>

</xsl:if>

</xsl:template>

</xsl:stylesheet>

against this:

<?xml version="1.0" encoding="UTF-8"?>

<big>

<block>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.&#13;

&#13;ultrices nisl id orci. Curabitur id est. In eget mauris. Lorem
Praesent sollicitudin bibendum orci. Suspendisse potenti. Quisque nec
tortor.&#13;

&#13;magna. Sed facilisis nonummy nulla. Aenean feugiat, ligula sit amet
rhoncus consectetuer, mi pede consectetuer neque, vitae gravida urna
diam ac massa. Lorem Aenean neque magna, gravida vitae, pellentesque
nec, aliquam a, risus.&#13;

&#13;

</block>

</big>


I get this (all the whitespace included):
 

<div><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

 

 

ultrices nisl id orci. Curabitur id est. In eget mauris. Lorem Praesent
sollicitudin bibendum orci. Suspendisse potenti. Quisque nec tortor.

 

magna. Sed facilisis nonummy nulla. Aenean feugiat, ligula sit amet
rhoncus consectetuer, mi pede consectetuer neque, vitae gravida urna
diam ac massa. Lorem Aenean neque magna, gravida vitae, pellentesque
nec, aliquam a, risus.

 

 

</p>

</div>

Any help would be much appreciated.



On Mon, 2005-02-14 at 19:38 +0100, Joris Gillis wrote:
> Tempore 19:07:22, die 02/14/2005 AD, hinc in  
> xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Wagstaff, Jason  
> <WagstaffJ@xxxxxxxxxxxx>:
> 
> > I have a text block that contains &#13; &#13; wherever the user wanted
> > it to look like a paragraph break. I don't any have control over the
> > input.
> >
> > Any ideas on how can I replace &#13; with <br/>? Or better still, use
> > the &#13 to identify the paragraphs and wrap each <p>paragraph</p>?
> Hi,
> 
> Let's assume you have an XML with this node in it:
> 
> <text>Line1&#13;Line2&#13;other content</text>
> 
> 
> And the desired output would be:
> <div>
> 	<p>Line1</p>
> 	<p>Line2</p>
> 	<p>other content</p>
> </div>
> 
> 
> This can be achieved by applying a stylesheet like this:
> 
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
> version="1.0">
> <xsl:output method="xml" indent="yes"/>
> 
> <xsl:template match="text">
> <div>
> 	<xsl:call-template name="par"/>
> </div>
> </xsl:template>
> 
> <xsl:template name="par">
> 	<xsl:param name="text" select="."/>
> 	<p>
> 		<xsl:value-of select="substring-before(concat($text,'&#13;'),'&#13;')"/>
> 	</p>
> 	<xsl:if test="contains($text,'&#13;')">
> 		<xsl:call-template name="par">
> 			<xsl:with-param name="text">
> 				<xsl:value-of select="substring-after($text,'&#13;')"/>
> 			</xsl:with-param>
> 		</xsl:call-template>
> 	</xsl:if>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> 
> regards,

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.