cancel
Showing results for 
Search instead for 
Did you mean: 

user defined function in xslt mapping

Former Member
0 Kudos

Hi Experts,

i am using xsl:stylesheet version="1.0"

I have created  a user defined "my:func" with no arguments and calling it .

......................................................................

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://xmlns.opentechnology.org/xslt-extensions/common">

    <exsl:function name="my:func">

   <exsl:result select="myName" />

  </exsl:function>

    <xsl:template match="/" xml:space="">

        <Name>

                    <xsl:value-of select="myfunc()"/>

        </Name>

    </xsl:template>

</xsl:stylesheet>

............................................................

and want as

<Name>

MyName

</Name>

But I am getting following error

"Transformer exception occurred when executing XSLT" .

please help me  on this..

thanks and regards

anup banerjee

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member184681
Active Contributor
0 Kudos

Hi,

I believe you have at least three fundamental problems with your XSLT Code:

  1. You did not declare the "my" namespace that you used for your custom function (my:func).
  2. For returning results from a function, exsl:return should be used instead of exsl:result (see more details i.e. here: http://xml.coverpages.org/jenitennison-exsl200102.html).
  3. When calling the custom function, the statement should be: my:func() (you are missing the colon ":" inside).

Hope this helps,
Greg

Former Member
0 Kudos

Hi Greg,

thanks for  your reply

when checking altova it shows the following error.

Error in XPath expression

Unknown function - Name and number of arguments do not match any function signature in the static context - 'func'

I am using simple function name no  any name space for declaraing function

as..

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://xmlns.opentechnology.org/xslt-extensions/common">

    <exsl:function name="func">

        <exsl:return select="myName"/>

    </exsl:function>

    <xsl:template match="/" xml:space="">

        <Name>

            <xsl:value-of select="func()"/>

        </Name>

    </xsl:template>

</xsl:stylesheet>

please help me regarding this...

thanks and regards,

Anup banerjee

former_member184681
Active Contributor
0 Kudos

You can try adding a dummy namespace, like below, maybe this will help:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://xmlns.opentechnology.org/xslt-extensions/common" xmlns:own="http://customfunctions.com/">
    <exsl:function name="own:func">
        <exsl:return select="myName"/>
    </exsl:function>
    <xsl:template match="/" xml:space="">
        <Name>
            <xsl:value-of select="own:func()"/>
        </Name>
    </xsl:template>
</xsl:stylesheet>

Hope this helps,
Greg

Former Member
0 Kudos

hi greg ,

I am getting the same error in altova

and when i am testing in my ESR geting the following error.

unable to find resource.

    

thanks and regards,

anup banerjee

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Hope you test the XSL file along with XML (schema instance) file for the resource.  Check the syntax of the below line

<exsl:return select="myName"/>

Example: Do you need any prefix like "something:myName"    or  using parameter and in this case

$myName.  Just throwing at ideas.

Former Member
0 Kudos

no i just want to return "MyName" as string to that function

but its throwing the error that is ....

Error in XPath expression

Unknown function - Name and number of arguments do not match any function signature in the static context - 'func'

thanks and regards ,

anup banerjee

iaki_vila
Active Contributor
0 Kudos

HI anup kumar banerjeem,

If you java class is like:

     public static String myFunc (String first, String last)

You should call from XSL like:

<xsl:value-of select ="javamap:myFunc($first, $last)"/>

Regards

Former Member
0 Kudos

mightbe issue with xsl mapping and Just try to check the mapping program in you XML SPY and check working fine / not ?

pls refer below blog:

http://scn.sap.com/thread/1658795