Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何将一个XSL文件包含到另一个XSL文件中_Xml_Xslt_Xslt 2.0 - Fatal编程技术网

Xml 如何将一个XSL文件包含到另一个XSL文件中

Xml 如何将一个XSL文件包含到另一个XSL文件中,xml,xslt,xslt-2.0,Xml,Xslt,Xslt 2.0,我需要2.xsl文件使用函数从文件1.xsl更改日期格式(标记)。我使用指令,但我不知道应该更改什么 这是我的XML文件: <?xml version="1.0" encoding="UTF-8"?> <ClientList> <Client> <Name>Jan</Name> <Surname>Kowalski</Surname> <Date>

我需要
2.xsl
文件使用函数从文件
1.xsl
更改日期格式(标记
)。我使用指令
,但我不知道应该更改什么

这是我的XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<ClientList>
    <Client>
        <Name>Jan</Name>
        <Surname>Kowalski</Surname>
        <Date>2018-03-23</Date>
    </Client>
    <Client>
        <Name>Piotr</Name>
        <Surname>Nowak</Surname>
        <Date>2018-04-25</Date>
    </Client>
</ClientList>
这是我的
2.xsl
文件(我需要该文件使用
1.xsl
中的函数):


由@Martin Honnen在其有关
1.xsl的评论中创建并正确指出的xsl有几个问题

格式转换逻辑需要包装在
中。下面是使用
的更新的
1.xsl

<xsl:template name="DateConvertor">
    <Date>
        <xsl:value-of select="concat(substring(Date, 9, 2), '-', substring(Date, 6, 2), '-', substring(Date, 1, 4))"/>
    </Date>
</xsl:template>
编辑-更改使用

XSLT2.0允许使用
编写自己的函数。函数可用于执行任何计算逻辑,并基于计算返回值。可以使用
将参数传递给函数。函数必须与不同于XSLT名称空间的名称空间相关联

需要修改
1.xsl
以包含一个函数,该函数接受
string
类型的单个参数,并返回
string
类型的值

<xsl:function name="ex:DateConvertor" as="xs:string">
    <xsl:param name="InputDate" as="xs:string" />
    <xsl:value-of select="concat(substring($InputDate, 9, 2), '-', substring($InputDate, 6, 2), '-', substring($InputDate, 1, 4))"/>
</xsl:function>
更改
2.xsl
以调用函数
ex:DateConvertor

映射函数所需的命名空间

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ex="http://canbeanything">

所需的输出可以在单个XSL中实现,但我假设这是一个学习阶段,上面可能是

的一个示例@Martin Honnen在其与
1.XSL
相关的评论中正确地指出了创建的XSL的几个问题

<xsl:template name="DateConvertor">
    <Date>
        <xsl:value-of select="concat(substring(Date, 9, 2), '-', substring(Date, 6, 2), '-', substring(Date, 1, 4))"/>
    </Date>
</xsl:template>
格式转换逻辑需要包装在
中。下面是使用
的更新的
1.xsl

<xsl:template name="DateConvertor">
    <Date>
        <xsl:value-of select="concat(substring(Date, 9, 2), '-', substring(Date, 6, 2), '-', substring(Date, 1, 4))"/>
    </Date>
</xsl:template>
编辑-更改使用

XSLT2.0允许使用
编写自己的函数。函数可用于执行任何计算逻辑,并基于计算返回值。可以使用
将参数传递给函数。函数必须与不同于XSLT名称空间的名称空间相关联

需要修改
1.xsl
以包含一个函数,该函数接受
string
类型的单个参数,并返回
string
类型的值

<xsl:function name="ex:DateConvertor" as="xs:string">
    <xsl:param name="InputDate" as="xs:string" />
    <xsl:value-of select="concat(substring($InputDate, 9, 2), '-', substring($InputDate, 6, 2), '-', substring($InputDate, 1, 4))"/>
</xsl:function>
更改
2.xsl
以调用函数
ex:DateConvertor

映射函数所需的命名空间

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ex="http://canbeanything">

所需的输出可以在单个XSL中实现,但我假设这是一个学习阶段,上面可能是

的一个示例,我在第一个XSLT片段中没有看到任何可用的代码,如果要定义函数,请使用
XSL:function
,如果要定义模板,请使用
xsl:template
。但是,甚至不允许使用顶级的
Date
元素,因此在考虑包含样式表之前,您首先需要编写一个符合XSLT规则的样式表。我在第一个XSLT片段中没有看到任何可用的代码,如果要定义函数,请使用
xsl:function
,如果要定义模板,请使用
xsl:template
。但是,甚至不允许使用顶级的
日期
元素,因此在考虑包含样式表之前,您首先需要编写一个符合XSLT规则的样式表。您能告诉我如何使用此函数吗?更新了答案以包含
的使用。有关用户定义的
的更多详细信息,请告诉我如何使用该功能?更新了答案以包括
的使用。有关用户定义的
的更多详细信息,请参见
<xsl:template name="DateConvertor">
    <Date>
        <xsl:value-of select="concat(substring(Date, 9, 2), '-', substring(Date, 6, 2), '-', substring(Date, 1, 4))"/>
    </Date>
</xsl:template>