[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Selecting text between two tags
On 8/6/06, Petar Tahchiev <paranoiabla@xxxxxxxxx> wrote:
Here is my problem: I have an html file that has a structure like this: <html> <body> <h2>Description</h2> <p>Blah-blah</p> Some-more <p>-s and text <h2>Parameters</h2> <p>Some more text<p> </body> </html> Given this XML (XHTML) file: <html> <body> <h2>Description</h2> <p>Blah-blah</p> Some-more <p/>-s and text <h2>Parameters</h2> <p>Some more text</p> </body> </html> The following stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://dummy"> <xsl:output method="xml" indent="yes" /> <xsl:template match="/"> <m:man> <xsl:apply-templates select="//h2[1]" /> </m:man> </xsl:template> <xsl:template match="h2"> <m:description> <xsl:call-template name="ExtractText"> <xsl:with-param name="node-set" select="following-sibling::node()" /> </xsl:call-template> </m:description> </xsl:template> <xsl:template name="ExtractText"> <xsl:param name="node-set" /> <xsl:if test="not($node-set[1]/self::h2)"> <xsl:copy-of select="$node-set[1]" /> <xsl:call-template name="ExtractText"> <xsl:with-param name="node-set" select="$node-set[position() > 1]" /> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> Produces output: <?xml version="1.0" encoding="UTF-8"?> <m:man xmlns:m="http://dummy"> <m:description> <p>Blah-blah</p> Some-more <p/>-s and text </m:description> </m:man> Hope this helps. -- Regards, Mukul Gandhi http://gandhimukul.tripod.com
|
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
|