Subject: Re: [xsl] Selecting text between two tags From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Sun, 6 Aug 2006 21:42:19 +0530 |
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>
Now i want to make a xml file that has this structure: <m:man> <m:description> <p>Blah-blah</p> Some-more <p>-s and text </m:description> <some other> things So my question is how to get the text between the first <h2>description</h2> and the second <h2>parameters</h2> tag and place it in the <m:description></m:description> tag
<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>
<?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: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>
<?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>
-- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Selecting text between two ta, Petar Tahchiev | Thread | Re: [xsl] Selecting text between tw, Petar Tahchiev |
[xsl] Selecting text between two ta, Petar Tahchiev | Date | Re: [xsl] Selecting text between tw, Petar Tahchiev |
Month |