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 July 19th, 2005, 03:37 PM
Authorized User
 
Join Date: Jun 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Functions replace and tokenize not found.

I want to take a string and replace every time two commas next to each other with this: ',0,'. Then I need to tokenize this string. This may soud very easy but I am having some difficulty. This is my code:

<xsl:variable name="path" select="tokenize(replace( @path, ',,', ' 0 '), ',')" />

Here is the error message that I get:
XPathParserException: The function '{0}' was not found. expression = 'tokenize(replace( @path, ',,', ' 0 '), ',')' Remaining tokens are ('tokenize' '(' 'replace' '(' '@' 'path' ',' '',,'' ',' '' 0 '' ')' ',' '',''')') (w2dxf.xsl, line 994, column 84)

I have tried with and without the tokenize function and I get the message that the function was not found.
I am using Xalan C 2.6, which only supports XSLT 1.0 XPath 1.0. After looking on the W3 website, I think that using something that is not up-to-date may be the problem. Does anyone have any solutions of getting around this problem?
Thanks to anyone that can give any help! have a great day!

 
Old July 20th, 2005, 01:31 PM
Authorized User
 
Join Date: Jun 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well... i think that i have solved my own problem. I have created a template that will work just as well as the one from EXSLT. If anyone is interested is using it, here is the code:

            <xsl:call-template name="replace">
                <xsl:with-param name="string" select="@path"/>
                <xsl:with-param name="search" select="$find"/>
                <xsl:with-param name="replace" select="$replace"/>
             </xsl:call-template

<xsl:template name="replace">
        <xsl:param name="string"/>
        <xsl:param name="search"/>
        <xsl:param name="replace"/>
        <xsl:choose>
              <xsl:when test="contains( $string, $search)">
                <xsl:variable name="before" select="substring-before( $string, $search)"/>
                <xsl:variable name="after" select="substring-after($string,$search)"/>
                       <xsl:call-template name="replace">
                    <xsl:with-param name="string" select="concat($before, $replace, $after)"/>
                    <xsl:with-param name="search" select="$search"/>
                    <xsl:with-param name="replace" select="$replace"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                     <xsl:value-of select="$string" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


 
Old July 20th, 2005, 02:51 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The functions replace() and tokenize() are XPath 2.0 functions, and if you get a message saying they haven't been found, this is because you are using an XPath 1.0 implementation.

Xalan implements XSLT 1.0 and XPath 1.0. If you want to use the 2.0 version, use Saxon.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
tokenize bbvic XSLT 1 July 19th, 2007 04:10 PM
<xsl:for-each select="tokenize($indoc,'&#xA;')"> kapy_kal XSLT 4 June 9th, 2006 07:33 AM
tokenize sakura C# 1 December 3rd, 2005 10:43 AM
Replace . by , Lukas C# 1 October 24th, 2003 10:44 PM





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