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

Subject: Re: [xsl] substring-before doesn't copy node
From: Marco <spinmar@xxxxxxxxx>
Date: Fri, 12 Jan 2007 14:51:28 +0100
Hi,
sorry for my mail but I  thought that my problem was clear. :-[
Following your  advice, I wrote the following template which should be
used to highligh one or more words inside a string.
My template has a problem: if the string has two times the same word
only the first is highlighted.
Suppose to have a simple XML:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
   <Query>pippo pluto</Query>
   <Url>http://dominio.com/pippo/pluto.html</Url>
</Root>

and my xsl is:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:date="http://exslt.org/dates-and-times";
extension-element-prefixes="date exsl"
xmlns:str="http://exslt.org/strings"; exclude-result-prefixes="str"
xmlns:exsl="http://exslt.org/common"; version="1.0">

<xsl:output method="html" indent="no" encoding="UTF-8"/>

<xsl:variable name="xsltsl-str-lower"
select="'&#x0061;&#x0062;&#x0063;&#x0064;&#x0065;&#x0066;&#x0067;&#x0068;&#x0
069;&#x006A;&#x006B;&#x006C;&#x006D;&#x006E;&#x006F;&#x0070;&#x0071;&#x0072;&
#x0073;&#x0074;&#x0075;&#x0076;&#x0077;&#x0078;&#x0079;&#x007A;&#x00B5;&#x00E
0;&#x00E1;&#x00E2;&#x00E3;&#x00E4;&#x00E5;&#x00E6;&#x00E7;&#x00E8;&#x00E9;&#x
00EA;&#x00EB;&#x00EC;&#x00ED;&#x00EE;&#x00EF;&#x00F0;&#x00F1;&#x00F2;&#x00F3;
&#x00F4;&#x00F5;&#x00F6;&#x00F8;&#x00F9;&#x00FA;&#x00FB;&#x00FC;&#x00FD;&#x00
FE;&#x00FF;&#x0101;&#x0103;&#x0105;&#x0107;&#x0109;&#x010B;&#x010D;&#x010F;&#
x0111;&#x0113;&#x0115;&#x0117;&#x0119;&#x011B;&#x011D;&#x011F;&#x0121;&#x0123
;&#x0125;&#x0127;&#x0129;&#x012B;&#x012D;&#x012F;&#x0131;&#x0133;&#x0135;&#x0
137;&#x013A;&#x013C;&#x013E;&#x0140;&#x0142;&#x0144;&#x0146;&#x0148;&#x014B;&
#x014D;&#x014F;&#x0151;&#x0153;&#x0155;&#x0157;&#x0159;&#x015B;&#x015D;&#x015
F;&#x0161;&#x0163;&#x0165;&#x0167;&#x0169;&#x016B;&#x016D;&#x016F;&#x0171;&#x
0173;&#x0175;&#x0177;&#x017A;&#x017C;&#x017E;&#x017F;&#x0183;&#x0185;&#x0188;
&#x018C;&#x0192;&#x0195;&#x0199;&#x01A1;&#x01A3;&#x01A5;&#x01A8;&#x01AD;&#x01
B0;&#x01B4;&#x01B6;&#x01B9;&#x01BD;&#x01BF;&#x01C5;&#x01C6;&#x01C8;&#x01C9;&#
x01CB;&#x01CC;&#x01CE;&#x01D0;&#x01D2;&#x01D4;&#x01D6;&#x01D8;&#x01DA;&#x01DC
;&#x01DD;&#x01DF;&#x01E1;&#x01E3;&#x01E5;&#x01E7;&#x01E9;&#x01EB;&#x01ED;&#x0
1EF;&#x01F2;&#x01F3;&#x01F5;&#x01F9;&#x01FB;&#x01FD;&#x01FF;&#x0201;&#x0203;&
#x0205;&#x0207;&#x0209;&#x020B;&#x020D;&#x020F;&#x0211;&#x0213;&#x0215;&#x021
7;&#x0219;&#x021B;&#x021D;&#x021F;&#x0223;&#x0225;&#x0227;&#x0229;&#x022B;&#x
022D;&#x022F;&#x0231;&#x0233;&#x0253;&#x0254;&#x0256;&#x0257;&#x0259;&#x025B;
&#x0260;&#x0263;&#x0268;&#x0269;&#x026F;&#x0272;&#x0275;&#x0280;&#x0283;&#x02
88;&#x028A;&#x028B;&#x0292;&#x0345;&#x03AC;&#x03AD;&#x03AE;&#x03AF;&#x03B1;&#
x03B2;&#x03B3;&#x03B4;&#x03B5;&#x03B6;&#x03B7;&#x03B8;&#x03B9;&#x03BA;&#x03BB
;&#x03BC;&#x03BD;&#x03BE;&#x03BF;&#x03C0;&#x03C1;&#x03C2;&#x03C3;&#x03C4;&#x0
3C5;&#x03C6;&#x03C7;&#x03C8;&#x03C9;&#x03CA;&#x03CB;&#x03CC;&#x03CD;&#x03CE;&
#x03D0;&#x03D1;&#x03D5;&#x03D6;&#x03DB;&#x03DD;&#x03DF;&#x03E1;&#x03E3;&#x03E
5;&#x03E7;&#x03E9;&#x03EB;&#x03ED;&#x03EF;&#x03F0;&#x03F1;&#x03F2;&#x03F5;&#x
0430;&#x0431;&#x0432;&#x0433;&#x0434;&#x0435;&#x0436;&#x0437;&#x0438;&#x0439;
&#x043A;&#x043B;&#x043C;&#x043D;&#x043E;&#x043F;&#x0440;&#x0441;&#x0442;&#x04
43;&#x0444;&#x0445;&#x0446;&#x0447;&#x0448;&#x0449;&#x044A;&#x044B;&#x044C;&#
x044D;&#x044E;&#x044F;&#x0450;&#x0451;&#x0452;&#x0453;&#x0454;&#x0455;&#x0456
;&#x0457;&#x0458;&#x0459;&#x045A;&#x045B;&#x045C;&#x045D;&#x045E;&#x045F;&#x0
461;&#x0463;&#x0465;&#x0467;&#x0469;&#x046B;&#x046D;&#x046F;&#x0471;&#x0473;&
#x0475;&#x0477;&#x0479;&#x047B;&#x047D;&#x047F;&#x0481;&#x048D;&#x048F;&#x049
1;&#x0493;&#x0495;&#x0497;&#x0499;&#x049B;&#x049D;&#x049F;&#x04A1;&#x04A3;&#x
04A5;&#x04A7;&#x04A9;&#x04AB;&#x04AD;&#x04AF;&#x04B1;&#x04B3;&#x04B5;&#x04B7;
&#x04B9;&#x04BB;&#x04BD;&#x04BF;&#x04C2;&#x04C4;&#x04C8;&#x04CC;&#x04D1;&#x04
D3;&#x04D5;&#x04D7;&#x04D9;&#x04DB;&#x04DD;&#x04DF;&#x04E1;&#x04E3;&#x04E5;&#
x04E7;&#x04E9;&#x04EB;&#x04ED;&#x04EF;&#x04F1;&#x04F3;&#x04F5;&#x04F9;&#x0561
;&#x0562;&#x0563;&#x0564;&#x0565;&#x0566;&#x0567;&#x0568;&#x0569;&#x056A;&#x0
56B;&#x056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1EE9;&#x1EEB;&#x1EED;&#x1EEF;&#x1EF1
;&#x1EF3;&#x1EF5;&#x1EF7;&#x1EF9;&#x1F00;&#x1F01;&#x1F02;&#x1F03;&#x1F04;&#x1
F05;&#x1F06;&#x1F07;&#x1F10;&#x1F11;&#x1F12;&#x1F13;&#x1F14;&#x1F15;&#x1F20;&
#x1F21;&#x1F22;&#x1F23;&#x1F24;&#x1F25;&#x1F26;&#x1F27;&#x1F30;&#x1F31;&#x1F3
2;&#x1F33;&#x1F34;&#x1F35;&#x1F36;&#x1F37;&#x1F40;&#x1F41;&#x1F42;&#x1F43;&#x
1F44;&#x1F45;&#x1F51;&#x1F53;&#x1F55;&#x1F57;&#x1F60;&#x1F61;&#x1F62;&#x1F63;
&#x1F64;&#x1F65;&#x1F66;&#x1F67;&#x1F70;&#x1F71;&#x1F72;&#x1F73;&#x1F74;&#x1F
75;&#x1F76;&#x1F77;&#x1F78;&#x1F79;&#x1F7A;&#x1F7B;&#x1F7C;&#x1F7D;&#x1F80;&#
x1F81;&#x1F82;&#x1F83;&#x1F84;&#x1F85;&#x1F86;&#x1F87;&#x1F90;&#x1F91;&#x1F92
;&#x1F93;&#x1F94;&#x1F95;&#x1F96;&#x1F97;&#x1FA0;&#x1FA1;&#x1FA2;&#x1FA3;&#x1
FA4;&#x1FA5;&#x1FA6;&#x1FA7;&#x1FB0;&#x1FB1;&#x1FB3;&#x1FBE;&#x1FC3;&#x1FD0;&
#x1FD1;&#x1FE0;&#x1FE1;&#x1FE5;&#x1FF3;&#x2170;&#x2171;&#x2172;&#x2173;&#x217
4;&#x2175;&#x2176;&#x2177;&#x2178;&#x2179;&#x217A;&#x217B;&#x217C;&#x217D;&#x
217E;&#x217F;&#x24D0;&#x24D1;&#x24D2;&#x24D3;&#x24D4;&#x24D5;&#x24D6;&#x24D7;
&#x24D8;&#x24D9;&#x24DA;&#x24DB;&#x24DC;&#x24DD;&#x24DE;&#x24DF;&#x24E0;&#x24
E1;&#x24E2;&#x24E3;&#x24E4;&#x24E5;&#x24E6;&#x24E7;&#x24E8;&#x24E9;&#xFF41;&#
xFF42;&#xFF43;&#xFF44;&#xFF45;&#xFF46;&#xFF47;&#xFF48;&#xFF49;&#xFF4A;&#xFF4B
;&#xFF4C;&#xFF4D;&#xFF4E;&#xFF4F;&#xFF50;&#xFF51;&#xFF52;&#xFF53;&#xFF54;&#xF
F55;&#xFF56;&#xFF57;&#xFF58;&#xFF59;&#xFF5A;&#x10428;&#x10429;&#x1042A;&#x104
2B;&#x1042C;&#x1042D;&#x1042E;&#x1042F;&#x10430;&#x10431;&#x10432;&#x10433;&#
x10434;&#x10435;&#x10436;&#x10437;&#x10438;&#x10439;&#x1043A;&#x1043B;&#x1043
C;&#x1043D;&#x1043E;&#x1043F;&#x10440;&#x10441;&#x10442;&#x10443;&#x10444;&#x
10445;&#x10446;&#x10447;&#x10448;&#x10449;&#x1044A;&#x1044B;&#x1044C;&#x1044D
;'"/>
 <xsl:variable name="xsltsl-str-upper"
select="'&#x0041;&#x0042;&#x0043;&#x0044;&#x0045;&#x0046;&#x0047;&#x0048;&#x0
049;&#x004A;&#x004B;&#x004C;&#x004D;&#x004E;&#x004F;&#x0050;&#x0051;&#x0052;&
#x0053;&#x0054;&#x0055;&#x0056;&#x0057;&#x0058;&#x0059;&#x005A;&#x039C;&#x00C
0;&#x00C1;&#x00C2;&#x00C3;&#x00C4;&#x00C5;&#x00C6;&#x00C7;&#x00C8;&#x00C9;&#x
00CA;&#x00CB;&#x00CC;&#x00CD;&#x00CE;&#x00CF;&#x00D0;&#x00D1;&#x00D2;&#x00D3;
&#x00D4;&#x00D5;&#x00D6;&#x00D8;&#x00D9;&#x00DA;&#x00DB;&#x00DC;&#x00DD;&#x00
DE;&#x0178;&#x0100;&#x0102;&#x0104;&#x0106;&#x0108;&#x010A;&#x010C;&#x010E;&#
x0110;&#x0112;&#x0114;&#x0116;&#x0118;&#x011A;&#x011C;&#x011E;&#x0120;&#x0122
;&#x0124;&#x0126;&#x0128;&#x012A;&#x012C;&#x012E;&#x0049;&#x0132;&#x0134;&#x0
136;&#x0139;&#x013B;&#x013D;&#x013F;&#x0141;&#x0143;&#x0145;&#x0147;&#x014A;&
#x014C;&#x014E;&#x0150;&#x0152;&#x0154;&#x0156;&#x0158;&#x015A;&#x015C;&#x015
E;&#x0160;&#x0162;&#x0164;&#x0166;&#x0168;&#x016A;&#x016C;&#x016E;&#x0170;&#x
0172;&#x0174;&#x0176;&#x0179;&#x017B;&#x017D;&#x0053;&#x0182;&#x0184;&#x0187;
&#x018B;&#x0191;&#x01F6;&#x0198;&#x01A0;&#x01A2;&#x01A4;&#x01A7;&#x01AC;&#x01
AF;&#x01B3;&#x01B5;&#x01B8;&#x01BC;&#x01F7;&#x01C4;&#x01C4;&#x01C7;&#x01C7;&#
x01CA;&#x01CA;&#x01CD;&#x01CF;&#x01D1;&#x01D3;&#x01D5;&#x01D7;&#x01D9;&#x01DB
;&#x018E;&#x01DE;&#x01E0;&#x01E2;&#x01E4;&#x01E6;&#x01E8;&#x01EA;&#x01EC;&#x0
1EE;&#x01F1;&#x01F1;&#x01F4;&#x01F8;&#x01FA;&#x01FC;&#x01FE;&#x0200;&#x0202;&
#x0204;&#x0206;&#x0208;&#x020A;&#x020C;&#x020E;&#x0210;&#x0212;&#x0214;&#x021
6;&#x0218;&#x021A;&#x021C;&#x021E;&#x0222;&#x0224;&#x0226;&#x0228;&#x022A;&#x
022C;&#x022E;&#x0230;&#x0232;&#x0181;&#x0186;&#x0189;&#x018A;&#x018F;&#x0190;
&#x0193;&#x0194;&#x0197;&#x0196;&#x019C;&#x019D;&#x019F;&#x01A6;&#x01A9;&#x01
AE;&#x01B1;&#x01B2;&#x01B7;&#x0399;&#x0386;&#x0388;&#x0389;&#x038A;&#x0391;&#
x0392;&#x0393;&#x0394;&#x0395;&#x0396;&#x0397;&#x0398;&#x0399;&#x039A;&#x039B
;&#x039C;&#x039D;&#x039E;&#x039F;&#x03A0;&#x03A1;&#x03A3;&#x03A3;&#x03A4;&#x0
3A5;&#x03A6;&#x03A7;&#x03A8;&#x03A9;&#x03AA;&#x03AB;&#x038C;&#x038E;&#x038F;&
#x0392;&#x0398;&#x03A6;&#x03A0;&#x03DA;&#x03DC;&#x03DE;&#x03E0;&#x03E2;&#x03E
4;&#x03E6;&#x03E8;&#x03EA;&#x03EC;&#x03EE;&#x039A;&#x03A1;&#x03A3;&#x0395;&#x
0410;&#x0411;&#x0412;&#x0413;&#x0414;&#x0415;&#x0416;&#x0417;&#x0418;&#x0419;
&#x041A;&#x041B;&#x041C;&#x041D;&#x041E;&#x041F;&#x0420;&#x0421;&#x0422;&#x04
23;&#x0424;&#x0425;&#x0426;&#x0427;&#x0428;&#x0429;&#x042A;&#x042B;&#x042C;&#
x042D;&#x042E;&#x042F;&#x0400;&#x0401;&#x0402;&#x0403;&#x0404;&#x0405;&#x0406
;&#x0407;&#x0408;&#x0409;&#x040A;&#x040B;&#x040C;&#x040D;&#x040E;&#x040F;&#x0
460;&#x0462;&#x0464;&#x0466;&#x0468;&#x046A;&#x046C;&#x046E;&#x0470;&#x0472;&
#x0474;&#x0476;&#x0478;&#x047A;&#x047C;&#x047E;&#x0480;&#x048C;&#x048E;&#x049
0;&#x0492;&#x0494;&#x0496;&#x0498;&#x049A;&#x049C;&#x049E;&#x04A0;&#x04A2;&#x
04A4;&#x04A6;&#x04A8;&#x04AA;&#x04AC;&#x04AE;&#x04B0;&#x04B2;&#x04B4;&#x04B6;
&#x04B8;&#x04BA;&#x04BC;&#x04BE;&#x04C1;&#x04C3;&#x04C7;&#x04CB;&#x04D0;&#x04
D2;&#x04D4;&#x04D6;&#x04D8;&#x04DA;&#x04DC;&#x04DE;&#x04E0;&#x04E2;&#x04E4;&#
x04E6;&#x04E8;&#x04EA;&#x04EC;&#x04EE;&#x04F0;&#x04F2;&#x04F4;&#x04F8;&#x0531
;&#x0532;&#x0533;&#x0534;&#x0535;&#x0536;&#x0537;&#x0538;&#x0539;&#x053A;&#x0
53B;&#x053C;&#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x24C3;&#x24C4;&#x24C5;&#x24C6;&#x24
C7;&#x24C8;&#x24C9;&#x24CA;&#x24CB;&#x24CC;&#x24CD;&#x24CE;&#x24CF;&#xFF21;&#
xFF22;&#xFF23;&#xFF24;&#xFF25;&#xFF26;&#xFF27;&#xFF28;&#xFF29;&#xFF2A;&#xFF2B
;&#xFF2C;&#xFF2D;&#xFF2E;&#xFF2F;&#xFF30;&#xFF31;&#xFF32;&#xFF33;&#xFF34;&#xF
F35;&#xFF36;&#xFF37;&#xFF38;&#xFF39;&#xFF3A;&#x10400;&#x10401;&#x10402;&#x104
03;&#x10404;&#x10405;&#x10406;&#x10407;&#x10408;&#x10409;&#x1040A;&#x1040B;&#
x1040C;&#x1040D;&#x1040E;&#x1040F;&#x10410;&#x10411;&#x10412;&#x10413;&#x1041
4;&#x10415;&#x10416;&#x10417;&#x10418;&#x10419;&#x1041A;&#x1041B;&#x1041C;&#x
1041D;&#x1041E;&#x1041F;&#x10420;&#x10421;&#x10422;&#x10423;&#x10424;&#x10425
;'"/>
 <xsl:variable name="xsltsl-str-digits" select="'0123456789'"/>
 <!-- space (#x20) characters, carriage returns, line feeds, or tabs. -->
 <xsl:variable name="xsltsl-str-ws" select="'&#x20;&#x9;&#xD;&#xA;'"/>


<xsl:template name="iol_make_lower"> <xsl:param name="text"/> <xsl:value-of select="translate($text, $xsltsl-str-upper, $xsltsl-str-lower)"/> </xsl:template>


<xsl:template name="highlighter"> <xsl:param name="text"/> <xsl:param name="what"/>

      <xsl:variable name="test-text">
          <xsl:call-template name="iol_make_lower">
              <xsl:with-param name="text" select="$text" />
          </xsl:call-template>
      </xsl:variable>

   <xsl:choose>
              <xsl:when test="contains($test-text,
exsl:node-set($what)/token[1])">
                      <xsl:variable name="before"
select="substring-before(string($test-text),
exsl:node-set($what)/token[1])"/>
                      <xsl:variable name="after"
select="substring-after($test-text, exsl:node-set($what)/token[1])"/>
                      <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(exsl:node-set($what)/token[1]) + 1)"/>

                      <xsl:variable name="temp">
                          <xsl:value-of select="concat($real-before,
'&lt;b&gt;', exsl:node-set($what)/token[1], '&lt;/b&gt;', $real-after)" />
                      </xsl:variable>

               <xsl:choose>
                   <xsl:when
test="count(exsl:node-set($what)/token[position() > 1] ) = 0">
                       <xsl:value-of select="$temp"
disable-output-escaping="yes" />
                   </xsl:when>
                   <xsl:otherwise>
                       <xsl:call-template name="highlighter">
                                  <xsl:with-param
name="text"><xsl:copy-of select="$temp" /></xsl:with-param>
                                      <xsl:with-param
name="what"><xsl:copy-of select="exsl:node-set($what)/token[position() >
1]" /></xsl:with-param>
                              </xsl:call-template>
                   </xsl:otherwise>
               </xsl:choose>
              </xsl:when>
              <xsl:otherwise>
                      <xsl:choose>
                   <xsl:when test="position() = last()">
                       <xsl:value-of select="$text"
disable-output-escaping="yes" />
                   </xsl:when>
                   <xsl:otherwise>
                       <xsl:call-template name="highlighter">
                                  <xsl:with-param
name="text"><xsl:copy-of select="$text" /></xsl:with-param>
                                      <xsl:with-param
name="what"><xsl:copy-of select="exsl:node-set($what)/token[position() >
1]" /></xsl:with-param>
                              </xsl:call-template>
                   </xsl:otherwise>
               </xsl:choose>
              </xsl:otherwise>
         </xsl:choose>
</xsl:template>

 <xsl:template name="main_highlighter">
      <xsl:param name="query"/>
   <xsl:param name="url"/>

   <xsl:variable name="url_decoded">
        <xsl:value-of select="str:decode-uri($url)" />
       <!--<xsl:value-of select="$url" />-->
   </xsl:variable>

    <xsl:variable name="test-what">
          <xsl:call-template name="iol_make_lower">
              <xsl:with-param name="text" select="$query" />
          </xsl:call-template>
      </xsl:variable>

   <xsl:choose>
       <xsl:when test="normalize-space($test-what)">
                <xsl:variable name="pp">
                   <xsl:copy-of
select="str:tokenize(string($test-what), ' ')" />
               </xsl:variable>
               <xsl:call-template name="highlighter">
                   <xsl:with-param name="text"><xsl:value-of
select="$url_decoded" /></xsl:with-param>
                   <xsl:with-param name="what"><xsl:copy-of
select="$pp"/></xsl:with-param>
               </xsl:call-template>
       </xsl:when>
       <xsl:otherwise>
           <xsl:value-of select="$url_decoded" />
       </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template match="/">
   <xsl:apply-templates select ="Root"/>
</xsl:template>

<xsl:template match="Root">
   <html>
       <head>
           <title>Temp</title>
       </head>
       <body>
       <p>
       <xsl:call-template name="main_highlighter">
           <xsl:with-param name="query"><xsl:value-of select="Query"
/></xsl:with-param>
           <xsl:with-param name="url"><xsl:value-of select="Url"
/></xsl:with-param>
       </xsl:call-template>
       </p>
       </body>
   </html>
</xsl:template>

</xsl:stylesheet>

In this case all is ok, but if the url is
<Url>http://dominio.com/pippo/pippo/pluto.html</Url> the output is:

...
<p>http://dominio.com/<b>pippo</b>/pippo/<b>pluto</b>.html</p>
.....

What could I do?
I'm using libxslt 1.1.15 as xslt engine.
Best regards

Marco

Michael Kay ha scritto:
You seem to be confused about the data model. Your title mentions "nodes",
but your message mentions "tags"; you seem to be in a state where you
half-know that the input is represented as a tree but you're still mentally
behaving as if it's all a single string in which elements are represented
by
textual markup.

You haven't really said what $test-text is, but my guess is that it's an
element node with three children, namely a text node containing
http://dominio.com/, an element node named b whose content is pippo, and a
text node whose content is /pluto.html. When you apply substring-before()
to
an element node, it converts the first argument to a string, which is done
by taking the string-value of the element node. This is the concatenation
of
all the text node descendants, namely
"http://dominio.com/pippo/pluto.html";.
So you lose the hierarchic structure of the input (or, as you put it, the
"tags").

If you want to process the text while retaining the structure of the tree,
then flattening the structure into a string isn't going to help. You need
to
process each text node individually. Of course, some things are going to be
very difficult to achieve, like highlighting the string "com/pip" which
straddles two nodes. Your first task is to specify what you want the output
to be in such cases.

Michael Kay
http://www.saxonica.com/


-----Original Message-----
From: Marco [mailto:spinmar@xxxxxxxxx]
Sent: 12 January 2007 09:36
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] substring-before doesn't copy node

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