Problem with EXSLT functions using 4xslt

  • Thread starter Prashanth Ellina
  • Start date
P

Prashanth Ellina

Hi,

When I try to run the following xsl on an xml with "<dummy></dummy>",
the 4xslt processor says "Undefined function: "testfn"". Any ideas?

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exslt = "http://exslt.org/common"
xmlns:func = "http://exslt.org/functions"
version="1.0">

<xsl:template match="/">
<xsl:value-of select="testfn()"/>
</xsl:template>

<func:function name="testfn">
<func:result>
<hello></hello>
</func:result>
</func:function>

</xsl:stylesheet>

Thanks in advance,
Prashanth
 
M

Martin Honnen

Prashanth Ellina wrote:

When I try to run the following xsl on an xml with "<dummy></dummy>",
the 4xslt processor says "Undefined function: "testfn"". Any ideas?

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exslt = "http://exslt.org/common"
xmlns:func = "http://exslt.org/functions"
version="1.0">

<xsl:template match="/">
<xsl:value-of select="testfn()"/>
</xsl:template>

<func:function name="testfn">
<func:result>
<hello></hello>
</func:result>
</func:function>

</xsl:stylesheet>

I don't use 4xslt but Saxon 6 also has support for the EXSLT functions,
here is a stylesheet that I think achieves what you want to do:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:func="http://exslt.org/functions"
xmlns:myfunctions="http://example.com/2005/08/functions"
extension-element-prefixes="func"
version="1.0">

<xsl:template match="/">
<results>
<xsl:copy-of select="myfunctions:testfn()"/>
</results>
</xsl:template>

<func:function name="myfunctions:testfn">
<func:result>
<hello></hello>
</func:result>
</func:function>

</xsl:stylesheet>

The result of that stylesheet run against any source document is

<?xml version="1.0" encoding="utf-8"?>
<results
xmlns:myfunctions="http://example.com/2005/08/functions"><hello/></results>

So you need to make sure that you
- define your own functions in a namespace
- have extension-element-prefixes="func" on the <xsl:stylesheet>
- be aware that an EXSLT function defined with func:function like the
testfn returns a nodeset, if you want to have a nodeset show up in
the result tree you need to use xsl:copy-of on the result of the
function call
 
P

Prashanth Ellina

So you need to make sure that you
- define your own functions in a namespace
- have extension-element-prefixes="func" on the <xsl:stylesheet>
- be aware that an EXSLT function defined with func:function like the
testfn returns a nodeset, if you want to have a nodeset show up in
the result tree you need to use xsl:copy-of on the result of the
function call

Wow! It works! Thank you :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top