[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Gregor,
If all <br/> elements are children of <body>, the following will work. On your input:
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 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:
If <br> elements could occur at any depth ... see this thread: http://www.biglist.com/lists/xsl-list/archives/200505/msg01413.html
Regards,
--A
_________________________________________________________________
Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/
RE: [xsl] Convert html:br to paragraphs
Subject: RE: [xsl] Convert html:br to paragraphs From: "Aron Bock" <aronbock@xxxxxxxxxxx> Date: Thu, 02 Jun 2005 01:08:02 +0000 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Convert html:br to paragraphs, gregor FELLENZ | Thread | RE: [xsl] Convert html:br to paragr, Michael Kay |
Re: [xsl] Frustrated with xxx:node-, Karl Stubsjoen | Date | [xsl] key() function issue, Bruce D'Arcus |
Month |
Keywords