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 XSLT未跨多个模板匹配进行排序_Xml_Xslt_Xslt 1.0 - Fatal编程技术网

Xml XSLT未跨多个模板匹配进行排序

Xml XSLT未跨多个模板匹配进行排序,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,XSLT1.0 我正在整理文本信息输出,并试图按日期列出sms和mms信息。 数据的结构类似于: <smses> <sms address="555555001" date="1517372455000" readable_date="Jan 30, 2018" message="Hello" name="John" /> <sms address="555555001" date="1517372455004" readable_date="J

XSLT1.0

我正在整理文本信息输出,并试图按日期列出sms和mms信息。 数据的结构类似于:

  <smses>
    <sms address="555555001" date="1517372455000" readable_date="Jan 30, 2018" message="Hello" name="John" />
    <sms address="555555001" date="1517372455004" readable_date="Jan 30, 2018" message="Hello" name="John" />
    <sms address="555555009" date="1517372458000" readable_date="Jan 30, 2018" message="Hello" name="Jane" />
    <sms address="555555009" date="1517372458001" readable_date="Jan 30, 2018" message="Hello" name="Jane" />
    <sms address="555555009" date="1517372458002" readable_date="Jan 30, 2018" message="Hello" name="Jane" />
    <sms address="555555001" date="1517372455005" readable_date="Jan 30, 2018" message="Hello" name="John" />
    <mms address="555555001" date="1517372455001" readable_date="Jan 30, 2018" message="Hello" name="John" />
    <mms address="555555001" date="1517372455002" readable_date="Jan 30, 2018" message="Hello" name="John" />
    <mms address="555555001" date="1517372455003" readable_date="Jan 30, 2018" message="Hello" name="John" />
   </smses>

我正在生成一个按“John”过滤的密钥(实际数据中存在@readable_date)



无论我怎么做,彩信总是在短信之后出现,而不是按日期对所有节点进行排序。

如果您只查找发送给
John
的邮件,我认为您不需要定义
。您可以应用
John
上过滤的
,然后在
@date
上应用排序。下面是XSLT模板

<xsl:template match="smses">
    <xsl:for-each select="*[@name='John']">
        <xsl:sort select="@date" order="ascending" data-type="number" />
        <output>
            <xsl:value-of select="@message" />
        </output>
    </xsl:for-each>
</xsl:template>
使用上述XML,当应用XSLT模板时,将生成以下排序的输出

<output>Hello, This is SMS 1 for John.</output>
<output>Hello, This is MMS 1 for John.</output>
<output>Hello, This is MMS 2 for John.</output>
<output>Hello, This is MMS 3 for John.</output>
<output>Hello, This is SMS 2 for John.</output>
<output>Hello, This is SMS 3 for John.</output>
你好,这里是约翰的短信1。
你好,我是约翰的彩信1。
你好,我是约翰的彩信2。
你好,我是约翰的彩信3。
你好,这是约翰的短信2。
你好,这是约翰的短信3。

您正在按
@readable\u date
对元素进行分组,并对组进行排序;然后输出每个组的内容,而无需进一步排序(即,每个组按文档顺序输出)


但是在您的示例数据中,所有元素都具有相同的@readable_日期,因此只有一个组,所以对组进行排序没有任何效果。您需要对组内的项进行排序,即
match=“sms | mms”
模板规则中的
xsl:for-each
指令需要一个
xsl:sort
规范。

您能基于输入XML共享所需的输出吗?共享XSLT代码有一些属性,即<代码>@联系人姓名,
@可读日期
,输入XML中不存在。这些是否要映射到
@name
@date
?@Aniket-V
@contact\u name
应该是
@name
。输出最终将成为表中的列表,并且应该只是按日期排序的邮件列表。是否需要先在
@name
上排序,然后再在
@date
上排序?不,我只需要按日期排序。我假设问题是在使用应用模板时应用多个匹配项。我不知道如何将两个比赛集排序为一个。谢谢。在for each中进行排序是成功的关键。你的建议将工作的信息提供,我的实际计划有一些额外的细节,需要模板。
<smses>
    <sms address="555555001" date="1517372455000" readable_date="Jan 30, 2018" message="Hello, This is SMS 1 for John." name="John" />
    <sms address="555555001" date="1517372455004" readable_date="Jan 30, 2018" message="Hello, This is SMS 2 for John." name="John" />
    <sms address="555555009" date="1517372458000" readable_date="Jan 30, 2018" message="Hello, This is SMS 1 for Jane." name="Jane" />
    <sms address="555555009" date="1517372458001" readable_date="Jan 30, 2018" message="Hello, This is SMS 2 for Jane." name="Jane" />
    <sms address="555555009" date="1517372458002" readable_date="Jan 30, 2018" message="Hello, This is SMS 3 for Jane." name="Jane" />
    <sms address="555555001" date="1517372455005" readable_date="Jan 30, 2018" message="Hello, This is SMS 3 for John." name="John" />
    <mms address="555555001" date="1517372455001" readable_date="Jan 30, 2018" message="Hello, This is MMS 1 for John." name="John" />
    <mms address="555555001" date="1517372455002" readable_date="Jan 30, 2018" message="Hello, This is MMS 2 for John." name="John" />
    <mms address="555555001" date="1517372455003" readable_date="Jan 30, 2018" message="Hello, This is MMS 3 for John." name="John" />
</smses>
<output>Hello, This is SMS 1 for John.</output>
<output>Hello, This is MMS 1 for John.</output>
<output>Hello, This is MMS 2 for John.</output>
<output>Hello, This is MMS 3 for John.</output>
<output>Hello, This is SMS 2 for John.</output>
<output>Hello, This is SMS 3 for John.</output>