Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 31st, 2006, 10:03 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default index-of() function in XSL2

Hallo all,

I have recently completed an AJAX SOAP file and now I am trying to generate the XSL s from the functions that I have used in my script.

I have written an indexOf function which cuts a string from the beginning of an character stream "-- " and takes it as 100 characters. It is like

myArray7[i] = xmldoc.selectNodes("//fcs:folder/fcs:folderHeadlinesResultSet/fcs:folderHeadline/fcs:snippet")[i];
            if(myArray7[i]==null){
                return false;
                }
            else{
                var cPos = myArray7[i].text.indexOf("-- ");
                if (cPos >= 0)
                    snippet[i] = myArray7[i].text.substring(cPos + 3,100 + cPos + 3);
                else
                    snippet[i] = myArray7[i].text.substring(0,100);
                myCell1.innerHTML += "<p>"+snippet[i]+"...</p>";
                }

What I tried to write in my XSL is:

      <tr>
                     <xsl:variable name="snippet" select="fcs:snippet"/>
                     <xsl:variable name="cPos" select="index-of($snippet, '-')"/>
                    <xsl:choose>
                        <xsl:when test="$cPos >= 0">
                            <xsl:variable name="cutSnippet" select="substring($snippet,$cPos+3,100+$cPos+3)"/>
                            <td class="text"><xsl:value-of select="$cutSnippet"/></td>
                        </xsl:when>
                        <xsl:otherwise>
                         <xsl:variable name="cutSnippet" select="substring($snippet,0,100)"/>
                          <td class="text"><xsl:value-of select="$cutSnippet"/></td>
                        </xsl:otherwise>
                    </xsl:choose>

                 </tr>

But it doesn't work. What am I doing wrong? Can anyone help me?

Your attitude determines your altitude
__________________
Your attitude determines your altitude
 
Old August 31st, 2006, 10:40 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The index-of function in XPath 2.0 finds the position(s) of an item in a sequence of items, it doesn't find the position of a character in a string.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 31st, 2006, 10:46 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much so I am clueless now how to find the index of this "-- " string in the element. What kind of function should I use for it?

Your attitude determines your altitude
 
Old August 31st, 2006, 11:11 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

try string-length(substring-before(x,y))

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 4th, 2006, 02:41 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much you solved my problem.

Your attitude determines your altitude





Similar Threads
Thread Thread Starter Forum Replies Last Post
Index carumuga SQL Server 2000 1 December 31st, 2007 12:42 PM
send variable in function to another function schoolBoy Javascript How-To 6 March 3rd, 2007 09:16 AM
dynamic sort - data-type (using xsl2.0 with saxon) ronisc XSLT 2 December 5th, 2006 05:39 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
retreive function/Line from macro or function? MikoMax J2EE 0 April 1st, 2004 04:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.