Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Convert html:br to paragraphs

From: "Aron Bock" <aronbock@----------->
To:
Date: 6/2/2005 1:08:00 AM
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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent