2011-06-10 108 views
0

我需要幫助。 我在一個名爲file_a.xsl的XSLT文件中定義了javascript。 我還有另一個名爲file_b.xslt的XSLT文件。 我一直在努力致電file_a.xsl中定義的sayHello()功能。從包含在主xslt文件中的外部xslt文件調用javascript函數

她是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> 

她是file_b.xsl

<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/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> 

我將竭誠爲解決此問題的幫助。

回答

0

即使我會更好地使用xsl:import而不是xsl:include,您的trasnforms是正確和完美的工作。我用MSXSL 4.0進行了測試,可能您使用的是過時版本。

結果是:

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

什麼問題呢?

0

我摔倒了這一點 - 我想這是你所需要的...
,因爲它顯示的xmlns:cosSin是命名空間 select語句調用使用cosSin功能:

工程在MS版本4前綴也....

...

<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> 
相關問題