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

RE: Convert html:br to paragraphs

Subject: RE: Convert html:br to paragraphs
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Thu, 02 Jun 2005 01:08:02 +0000
convert n to br
Gregor,

If all <br/> elements are children of <body>, the following will work. On your input:

<body>1. para is here <br/>
2. para is here and <b>bold</b> or another
inline element </body>

This XSL (inspired by http://www.biglist.com/lists/xsl-list/archives/200505/msg00146.html, which I've since learned is a fairly well-known technique):

<?xml version="1.0" encoding="iso8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>


   <xsl:template match="body">
       <xsl:copy>
           <xsl:call-template name="wrap">
               <xsl:with-param name="n" select="node()[1]"/>
           </xsl:call-template>
       </xsl:copy>
   </xsl:template>

<xsl:template name="wrap">
<xsl:param name="n" select="/.."/>
<xsl:param name="a" select="/.."/>
<xsl:choose>
<xsl:when test="$n[self::br]">
<p><xsl:copy-of select="$a"/></p>
<xsl:call-template name="wrap">
<xsl:with-param name="n" select="$n/following-sibling::node()[1]"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$n">
<xsl:call-template name="wrap">
<xsl:with-param name="n" select="$n/following-sibling::node()[1]"/>
<xsl:with-param name="a" select="$a|$n"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<p><xsl:copy-of select="$a"/></p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


</xsl:stylesheet>

produces:

<?xml version="1.0" encoding="UTF-8"?>
<body>
 <p>1. para is here </p>
 <p>
2. para is here and <b>bold</b> or another
inline element </p>
</body>

If <br> elements could occur at any depth ... see this thread: http://www.biglist.com/lists/xsl-list/archives/200505/msg01413.html

Regards,

--A


i have to convert <br/> structured html sites into documents with a
paragraph structure.

that means:

<body>1. para is here <br/>
2. para is here and <b>bold</b> or another
inline element </body>

has to be:

<p>1. para is here</p>
<p>2. para is here and <b>bold</b> or another
inline element</p>

_________________________________________________________________
Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/


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.