Re: [xsl] substring-before doesn't copy node

Subject: Re: [xsl] substring-before doesn't copy node
From: George Cristian Bina <george@xxxxxxxxxxxxx>
Date: Fri, 12 Jan 2007 11:51:57 +0200
Hi Marco,

Most probably the variable does not contain the text you think it contains. See below an example:

<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="/">
<xsl:variable name="test">http://dominio.com/&lt;b&gt;pippo&lt;/b&gt;/pluto.html</xsl:variable>
<result><xsl:value-of select="substring-before($test, 'pluto')"/></result>
</xsl:template>
</xsl:stylesheet>



Gives <result>http://dominio.com/&lt;b&gt;pippo&lt;/b&gt;/</result>

Test with that and see if you get different results.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


Marco wrote:
Hi,
I'm writing a recursive template and I have some problems with subtring-before.
I'm trying to write a words highlighter.
In my template if my text contains the word I'm looking for, I write:


<xsl:variable name="before" select="substring-before($test-text, .)" />
<xsl:variable name="after" select="substring-after($test-text, .)"/>
<xsl:variable name="real-before" select="substring($text, 1, string-length($before))"/>
<xsl:variable name="real-after" select="substring($text, string-length($before) + string-length(.) + 1)"/>


The problem is that my test-text contains for example http://dominio.com/&lt;b&gt;pippo&lt;/b&gt;/pluto.html and I'm looking for pluto, the before string is http://dominio.com/pippo/. It seems that substring-before deletes my tag <b></b>. I suppose that the problem is in the substring-after too.
I tried to write:
<xsl:variable name="before"><xsl:copy-of select="substring-before($test-text, .)" /></xsl:variable>
but the problem remains.
How could I solve my problem?
Best regards
Marco

Current Thread