我应该将 XSL 函数放在 XSL 文档中的什么位置?
我有一个 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 文件中。
I have an XSL style sheet for which I need to add some custom string manipulation using an xsl:function. But I am having trouble trying to work out where to put the function in my document.
My XSL simplified looks like this,
<?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>
And I want to put in a simple function, say,
<xsl:function name="my:helloWorld">
<xsl:text>Hello World!</xsl:text>
</xsl:function>
But I cannot work out where to put the function, when I put it under the node I get an error saying 'xsl:function' cannot be a child of the 'xsl:stylesheet' element., and if I put it under the node I get a similar error.
Where should I put the function? Idealy I would like to put my functions in an external file and import them into my xsl files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将样式表版本升级到2.0
然后在样式表声明中指定为
** 您的选择,您可以根据需要指定任何内容
然后在下面指定您的函数
然后在模板中您可以将其用作
You can upgrade the stylesheet version to 2.0
Then in stylesheet declaration specify as
** Your choice you can specify anything as your wish
then below this specify your function
Then in template you can use it as
XSL 1.0 版中没有 xsl:function。您必须创建一个命名模板
There is no xsl:function in XSL version 1.0. You have to create a named template