开发者

Calling javascript function from external xslt file that is included in a main xslt file

I need help please. I have javascript defined in an XSLT file called file_a.xsl. I have also a second XSLT file called file_b.xslt. I have been struggling to call the sayHello() function defined in file_a.xsl from file_b.xsl.

Her is file_a.xsl:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:foo="http://www.cateringportal.com/"
                   extension-element-prefixes="msxsl">



<msxsl:script language="javascript" implements-prefix="foo">
        <![CDATA[
        function sayHello()  
        {  
                return "hello there";  
        }  
        ]]>
      </msxsl:script>

</xsl:stylesheet>

Her is file_b.xsl:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.or开发者_运维问答g/1999/XSL/Transform"
xmlns:foo="http://www.cateringportal.com/" >
  <xsl:include href="helloXSL.xsl" />

<xsl:output method="html"/>
  <xsl:template match="/">
   <br/>


<xsl:value-of select="foo:sayHello()”/> 

  </xsl:template>
</xsl:stylesheet>

I will be happy for a help in solving this problem.


Even if I would use better xsl:import than xsl:include, your trasnforms are correct and perfectly working. I tested it with MSXSL 4.0, perhaps you are using an obsolete version.

The result is:

 <br xmlns:foo="http://www.cateringportal.com/">hello there

What's the problem there?


I fell over this - I think this is what you need ...
As it shows xmlns:cosSin is the namespace the select statement calls the function using cosSin: prefix

Works in MS version 4 also ....

...

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:cosSin="urn:cosSin">
...
 <text fill="white" stroke="none" font-size="48" text-anchor="middle">       
       <xsl:attribute name="x"><xsl:value-of select="(cosSin:returnX($offSet + ($slicePercentage div 2)) * 600) + 1000" /></xsl:attribute>
       <xsl:attribute name="y"><xsl:value-of select="(cosSin:returnY($offSet + ($slicePercentage div 2)) * 600) + 1000" /></xsl:attribute>
       <xsl:value-of select="$slicePercentage" /> %
     </text>
  ...
<msxsl:script language="JScript" implements-prefix="cosSin">
function returnX(percent) {
  var degree = percent * 3.6;
  return Math.cos(degree*Math.PI/180);
}
function returnY(percent) {
  var degree = percent * 3.6;
  return Math.sin(degree*Math.PI/180);
}
</msxsl:script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜