xsl-list
[Top] [All Lists]

Re: [xsl] tokenize and split

2009-02-06 07:07:07
Andy Chambers wrote:
Hi,

My problem is that I need to make a stylesheet which uses str:split
work on both saxon and
xalan processors.  I understand that saxon's tokenize is similar and
have been able to use it to make the stylesheet work on saxon.
However, I'm having difficulty working out how to use
function-available to invoke saxon's tokenize if it is available
otherwise use the str:split.

So I've got the following...

          <xsl:choose>
                <xsl:when test="function-available(str:split)">
                  <xsl:copy-of select="str:split('a b c', ' ')[1]"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:copy-of select="tokenize('a b c', ' ')[1]"/>
                </xsl:otherwise>
          </xsl:choose>

which runs fine in saxon but even though xalan wouldn't have to run
the tokenize function, it still
thinks there's a mistake because it doesn't recognize the function
tokenize.

Try whether
  <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:fn="http://www.w3.org/2005/xpath-functions";
    version="1.0">

  ...


          <xsl:choose>
                <xsl:when test="function-available('str:split')">
                  <xsl:copy-of select="str:split('a b c', ' ')[1]"/>
                </xsl:when>
                <xsl:when test="function-available('fn:tokenize')">
                  <xsl:copy-of select="fn:tokenize('a b c', ' ')[1]"/>
                </xsl:when>

works with Xalan.

--

        Martin Honnen
        http://JavaScript.FAQTs.com/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>