Subject: Re: [xsl] match string From: Zsolt Szabó <zsolt.szabo@xxxxxxxxxx> Date: Tue, 19 Oct 2004 14:27:16 +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:otherwise> <xsl:call-template name="para.template"> </xsl:call-template> </xsl:otherwise>
</xsl:choose> </xsl:template>
Hmmm... just after posting, I realized it's probably safer to use "normalize-space(.)", to ignore any leading whitespace:
<xsl:param name="split" select="3"/>
<xsl:template match="para">
<para><xsl:call-template name="splitwords"/></para>
</xsl:template>
<xsl:template name="splitwords">
<xsl:param name="i" select="0"/>
<xsl:param name="str1" select="''"/>
<xsl:param name="str2" select="normalize-space(.)"/>
<xsl:choose>
<xsl:when test="$i = $split">
<b><xsl:value-of select="$str1"/></b>
<xsl:value-of select="$str2"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains($str2,' ')">
<xsl:call-template name="splitwords">
<xsl:with-param name="i" select="$i+1"/>
<xsl:with-param name="str1" select="concat($str1,substring-before($str2,' '),' ')"/>
<xsl:with-param name="str2" select="substring-after($str2,' ')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="splitwords">
<xsl:with-param name="i" select="$split"/>
<xsl:with-param name="str1" select="concat($str1,$str2)"/>
<xsl:with-param name="str2" select="''"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Anton
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] match string, Anton Triest | Thread | Re: [xsl] match string, David Carlisle |
Re: [xsl] node lists, David Carlisle | Date | Re: [xsl] match string, David Carlisle |
Month |