Reputation: 4824
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?
Upvotes: 2
Views: 4563
Reputation: 163625
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.
Upvotes: 4
Reputation: 6825
i think you can check for the existence of the node just like this
<xsl:if test="first">
Upvotes: 3