Xslt XSL文档中的XSL函数应该放在哪里?
我有一个XSL样式表,需要使用XSL:函数为其添加一些自定义字符串操作。但是我在尝试将函数放在文档中的位置时遇到了困难 我的XSL简化如下所示Xslt XSL文档中的XSL函数应该放在哪里?,xslt,xsl-fo,Xslt,Xsl Fo,我有一个XSL样式表,需要使用XSL:函数为其添加一些自定义字符串操作。但是我在尝试将函数放在文档中的位置时遇到了困难 我的XSL简化如下所示 <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:my="myFunctions" xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:my="myFunctions" xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="Master.xslt"/>
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<!-- starts actual layout -->
<fo:page-sequence master-reference="first">
<fo:flow flow-name="xsl-region-body">
<!-- this defines a title level 1-->
<fo:block xsl:use-attribute-sets="heading">
HelloWorld
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
你好世界
我想用一个简单的函数,比如
<xsl:function name="my:helloWorld">
<xsl:text>Hello World!</xsl:text>
</xsl:function>
你好,世界!
但我无法确定将函数放在何处,当我将其放在节点下时,会出现一个错误,即“xsl:function”不能是“xsl:stylesheet”元素的子元素,如果将其放在节点下,则会出现类似的错误
我应该把函数放在哪里?理想情况下,我希望将我的函数放在一个外部文件中,并将它们导入xsl文件。xsl 1.0版中没有xsl:function。您必须创建一个命名模板
<xsl:template name="helloWorld">
<xsl:text>Hello World!</xsl:text>
</xsl:template>
(...)
<xsl:template match="something">
<xsl:call-template name="helloWorld"/>
</xsl:template>
你好,世界!
(...)
您可以将样式表版本升级到2.0
然后在样式表声明中指定为
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:func="http://www.**.com">
**您可以根据自己的意愿指定任何内容
然后在下面指定您的函数
<xsl:function name="func:helloWorld">
<xsl:text>Hello World!</xsl:text>
</xsl:function>
你好,世界!
然后在模板中,您可以将其用作
<xsl:template match="/">
<xsl:value-of select="func:helloWorld"/>
</xsl:template>
按照这里写的内容,我得到了一个“名称空间”。***.com不包含任何函数。错误。可能是什么问题?这是因为MSXML不支持XSLT 2。