XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Phil ParkerSubject: Replacing carriage returns and line breaks in XML with elements
Author: Phil Parker
Date: 24 Mar 2005 05:56 PM
From an authoring system, users are creating line breaks and carriage returns
within content that is then enclosed within in a single element upon export to
and XML file.

What is the best approach using XSLT, going from XML to XML, once the
line breaks and carriage returns are in the XML file to convert those
to elements.

For example:
<root>
<para>Here is beginning content
line break
Here is ending content
</para>
</root>

change to

<root>
<para>Here is beginning content</para>
<para>Here is ending content</para>
</root>

Phil

Posttop
(Deleted User) Subject: Replacing carriage returns and line breaks in XML with elements
Author: (Deleted User)
Date: 24 Mar 2005 07:22 PM
Try the the following piece of xslt. Please note it only does the <para> transform. I assume you know how to do other element.

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

<xsl:template match="para">
<xsl:call-template name="split">
<xsl:with-param name="str" select="text()"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="split">
<xsl:param name="str"/>
<xsl:if test="string-length($str) != 0">
<para><xsl:value-of select="substring-before($str, '&#xA;')"/>
</para>
<xsl:call-template name="split">
<xsl:with-param name="str" select="substring-after($str, '&#xA;')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

song

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.