johnware 0 Newbie Poster

Hi XSLT Gurus, I am creating html from xml.

I am calling a custom function to initialize the style attribute of a div element. This throws an exception during processing.
I call a built-in function to initialize the id attribute of the same div element and it works fine.

I am using eclipse with xalan 2.7.1 on win7.

The error is:

file:/C:/eclipsetest/deviceBookmarks/deviceBookmarks.xsl; Line #20; Column #79; javax.xml.transform.TransformerException: Instance method call to method widgetStyle requires an Object instance as first argument

My XSL is:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    xmlns:ns2="http://my.ns2.com" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:fn="http://www.w3.org/2005/xpath-functions" 
    exclude-result-prefixes="xsl fo fn xs ">    
    <xsl:function name="ns2:widgetStyle" >
        {top:4;left:5;}
    </xsl:function>

    <xsl:template match="/">
          <html><head><title>deviceBookmarks</title></head>
      <body>
         <div style="{ns2:widgetStyle()}" class="{@styleRef}" id="div{position()}">
                    <xsl:value-of select="label" />
         </div>
      </body></html>
    </xsl:template>

</xsl:stylesheet>

My XML is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:response xmlns:ns2="http://api.b.com/layout">
    <layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:type="ns2:OverlayPageType" version="1.0" id="ActionResponseOverlay">

        <style>
            <top>4</top>
            <height>22</height>
            <width>8</width>
            <horiz-align>left</horiz-align>
            <font-family>arial</font-family>
            <font-size>12</font-size>
        </style>
    </layout>
</ns2:response>

Could someone point me to a working example of: calling a custom function.

thanks, john

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.