Jatin Gadhiya
Jatin Gadhiya

Reputation: 2075

Why is the Replace function is not working in xslt 2.0

Replace function is not working in xslt 2.0

xslt looks like this:

 <xsl:stylesheet version='2.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:fn='http://www.w3.org/2005/xpath-funcations'>

    <xsl:output
           method="xml"
           encoding="utf-8"
           media-type="application/xml"
      />
      <xsl:template match='/'>

        <items>
             <xsl:apply-templates select="response/result/doc"/>
        </items>

      </xsl:template>

      <!-- search results xslt -->
      <xsl:template match="doc">

    <xsl:variable name="ShortDescription" select="str[@name = 'ShortDescription']"/>

    <shortdescription><xsl:value-of select="replace($ShortDescription, '&amp;amp;', '&amp;')" disable-output-escaping="yes"/></shortdescription>

    </xsl:template>

    </xsl:stylesheet>

When we use replace function we get this error:

enter image description here

and i am checking replace function on online xslt tester and some tool are given error and some are not why this?

www.utilities-online.info/xsltransformation/#.U-inrWNknIU   ==> given error
http://www.xsltcake.com/                                    ==> given error
http://xslt.online-toolz.com/tools/xslt-transformation.php  ==> given error
http://xslttest.appspot.com/                                ==> not given error.its working fine.
http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog ==> given error

and i am using solr 4.0 ,xslt 2.0 and xml 1.0

Please give me an idea of how to handle this replace function in xslt 2.0

Thanks in advance

Upvotes: 2

Views: 2141

Answers (1)

Abel
Abel

Reputation: 57169

www.utilities-online.info/xsltransformation/#.U-inrWNknIU ==> given error

That tool uses XSLT 1.0 (javax.xml.transform)

http://www.xsltcake.com/ ==> given error

That tool uses XSLT 1.0 (browser version, i.e. Transformiix in Firefox)

http://xslt.online-toolz.com/tools/xslt-transformation.php ==> given error

That tool uses XSLT 1.0 (libxsl)

http://xslttest.appspot.com/ ==> not given error.its working fine.

That tool uses XSLT 2.0 (SAXON 9.3.0.5 from Saxonica)

http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog ==> given error

That tool uses XSLT 1.0 (browser version, i.e. Transformiix in Firefox)

As others have already commented, the function fn:replace is a function added in XSLT 2.0 (actually, XPath 2.0, which is part of XSLT 2.0). Run your stylesheet with a 2.0 processor (like Saxon, Exselt or Altova) and you should be fine. How to configure it for your product depends on whether it supports using / plugging in a different processor.

Note: the namespace you use for fn is wrong. You do not need to specify that namespace (it's implicit), but if you do, use xmlns:fn="http://www.w3.org/2005/xpath-functions".

Upvotes: 2

Related Questions