我有一个 XSL 样式表,我需要使用 xsl:function 添加一些自定义字符串操作。但是我在尝试确定该函数在我的文档中的位置时遇到了麻烦。
我的 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: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 文件中。