Subject: Re: [xsl] match string From: Anton Triest <anton@xxxxxxxx> Date: Tue, 19 Oct 2004 15:39:58 +0200 |
Maybe I have found a solution. It works, at least with libxslt. is this correct? I think is is rather a hack.
<!--Select the first paragraph of all chapters--> <xsl:template match="//chapter/section[1]/para[1]" priority="1"> <xsl:call-template name="first_line"> <xsl:with-param name="string" select="."/> </xsl:call-template> </xsl:template>
<!--Select all other paragraphs--> <xsl:template match="//para"> <xsl:call-template name="para.template"> </xsl:call-template> </xsl:template>
<xsl:template name="first_line">
<xsl:param name="string"/>
<xsl:param name="string2"/>
<xsl:param name="string3"/>
<xsl:choose>
<!--are there any spaces???-->
<xsl:when test="contains($string, ' ')">
<div>
<b>
<!--1st word-->
<xsl:value-of select="substring-before($string,' ')"/>
<!--give back the space-->
<xsl:text> </xsl:text>
<!--2nd word-->
<xsl:value-of select="substring-before( substring-after ($string, ' '), ' ')"/>
<!--give back the space-->
<xsl:text> </xsl:text>
<!--3rd word-->
<xsl:value-of select="substring-before( substring-after ( substring-after ($string, ' '), ' '),' ')"/>
<!--give back the space-->
<xsl:text> </xsl:text>
</b>
</div>
</xsl:when>
<xsl:otherwise> <xsl:call-template name="para.template"> </xsl:call-template> </xsl:otherwise>
</xsl:choose> </xsl:template>
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>
<!-- identity template: copy all elements --> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template>
<!-- override on first paragraph of each chapter --> <xsl:template match="chapter/section[1]/para[1]//text()[1]"> <xsl:call-template name="splitwords"/> </xsl:template>
HTH, Anton
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] match string, Anton Triest | Thread | Re: [xsl] match string, Zsolt Szabó |
Re: [xsl] match string, David Carlisle | Date | Re: [xsl] match string, Zsolt Szabó |
Month |