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
如何使用XSLT1.0进行模板不匹配_Xslt_Conditional_Xslt 1.0 - Fatal编程技术网

如何使用XSLT1.0进行模板不匹配

如何使用XSLT1.0进行模板不匹配,xslt,conditional,xslt-1.0,Xslt,Conditional,Xslt 1.0,我有一个基于根元素标记处理消息的需求,为此,我基于根标记元素创建了3个不同的模板匹配。我想知道如果客户端发送的消息与根标记元素不匹配,如何处理该消息 输入: <?xml version="1.0"?> <process1 xmlns="http://www.openapplications.org/oagis/10" systemEnvironmentCode="Production" languageCode="en-US"> <Appdata>

我有一个基于根元素标记处理消息的需求,为此,我基于根标记元素创建了3个不同的模板匹配。我想知道如果客户端发送的消息与根标记元素不匹配,如何处理该消息

输入:

<?xml version="1.0"?>
<process1 xmlns="http://www.openapplications.org/oagis/10" systemEnvironmentCode="Production" languageCode="en-US">
    <Appdata>
        <Sender>
        </Sender>
        <Receiver>
        </Receiver>
        <CreationDateTime/>
    </Appdata>
</process1>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:template match="/*[local-name()='proces1']">
        <operation>dosomthing</operation>
    </xsl:template>
    <xsl:template match="/*[local-name()='process2']">
        <operation>dosomthing2</operation>
    </xsl:template>
    <xsl:template match="/*[local-name()='process2']">
        <operation>blah blah</operation>
    </xsl:template>
</xsl:stylesheet>
我这里的问题是,如果消息与3个模板process1、process2、process3不匹配,我想对其进行处理


有人能告诉我如何做到这一点吗?

首先,不要使用
local-name()
。声明和使用正确的名称空间很容易,请这样做

其次,只需制作一个不太具体的模板,以捕获任何具有您没有预料到的名称的文档元素(请参见下面的第四个模板):


dosomething1
dosomething2
dosomething3
注意:如果前三个模板的作用相同,则可以将它们折叠为一个模板

<xsl:template match="/oagis:process1|/oagis:process2|/oagis:process3">
    <operation>dosomething</operation>
</xsl:template>

剂量

根目录中的内部结构是否在所有情况下都相同?如果输入根元素是
/*
的优先级低于
/oagis:process1
”,但事实上它没有(没有斜杠,
*
的优先级低于
oagis:process1
)。我错了,规则在这里:。当多个匹配模板具有相同的优先级时,XSLT会打破这种束缚,选择最后定义的模板。因此,要么定义与
/*
匹配的模板,要么显式地为其分配低优先级。我把答案改成了后者。
<xsl:template match="/oagis:process1|/oagis:process2|/oagis:process3">
    <operation>dosomething</operation>
</xsl:template>