|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Convert html:br to paragraphs
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. _________________________________________________________________ Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








