2

Google turned up nil so here I am.

I'm working on an XSLT in Java. This is not the only XSLT in the project, and the others work great. My issue is as follows:

I'm getting a javax.xml.transform.TransformerException with the error message "Could not find function: exists". My XSLT is as follows:

<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xpath="http://www.w3.org/2005/xpath-functions" xmlns:java="java" 
xmlns:url="http://whatever/java/java.net.URLEncoder"
exclude-result-prefixes="url">

    <xsl:template match="User">
        <user>
            <id><xsl:value-of select="id"/></id>
            <xsl:if test="exists(first)"><first><xsl:value-of select="first"/></first></xsl:if>
        </user>
    </xsl:template>

</xsl:stylesheet>

The XML input is well formed, and if I remove the <xsl:if test="exists(first)"> line, everything works well.

As mentioned, I have other XSLTs that work well, including some that use the exists function. I checked the namespaces on the two, and they are identical.

Any idea what might be going on?

1
  • A solution probably would be test="first". As exists is XPath 2, could it be that this transformation is programmed differently, say with Xalan (XPath 1)? If another SPI like Xerces was left out. Commented Feb 23, 2012 at 18:52

2 Answers 2

4

exists() is an XPath 2.0 function, so the error message means that you are using an XSLT 1.0 processor. If you're working in Java, there's really no reason not to move forward to XSLT 2.0 - it will save you an immense amount of time.

Sign up to request clarification or add additional context in comments.

Comments

3

i think you can check for the existence of the node just like this

 <xsl:if test="first">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.