XSLT逻辑为具有相同日期和ID字段的元素组合添加序列

XSLT逻辑为具有相同日期和ID字段的元素组合添加序列,xslt,Xslt,我正在努力为转型创造逻辑 逻辑:“Seq”当ID和Date字段相等时,用于生成唯一键的序列号 <root> <Record> <ID>11</ID> <date>2020-03-11-07:00</date> <quantity>10</quantity> </Record> <Record>

我正在努力为转型创造逻辑

逻辑:“Seq”当ID和Date字段相等时,用于生成唯一键的序列号

<root>
    <Record>
        <ID>11</ID>
        <date>2020-03-11-07:00</date>
        <quantity>10</quantity>
    </Record>
    <Record>
        <ID>13</ID>
        <date>2020-03-12-07:00</date>
        <quantity>20</quantity>
    </Record>
    <Record>
        <ID>15</ID>
        <date>2020-03-13-07:00</date>
        <quantity>40</quantity>
    </Record>
    <Record>
        <ID>11</ID>
        <date>2020-03-11-07:00</date>
        <quantity>5</quantity>
    </Record>
    <Record>
        <ID>13</ID>
        <date>2020-03-17-07:00</date>
        <quantity>100</quantity>
    </Record>
</root>

在XSLT 3中,这是一个简单的组合键分组问题:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="#all"
    version="3.0">

  <xsl:output method="text" />

  <xsl:template match="root">
    <xsl:text>ID,seq,Date,quantity&#10;</xsl:text>
    <xsl:for-each-group select="Record" composite="yes" group-by="ID, date">
        <xsl:apply-templates select="current-group()"/>
    </xsl:for-each-group>
  </xsl:template>

  <xsl:template match="Record">
      <xsl:value-of select="ID, position(), date, quantity" separator=","/>
      <xsl:text>&#10;</xsl:text>
  </xsl:template>

</xsl:stylesheet>

ID、序号、日期、数量和#10;


XSLT 3可以与Saxon 9.8及更高版本或AltovaXML 2017 R3或更高版本一起使用

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="#all"
    version="3.0">

  <xsl:output method="text" />

  <xsl:template match="root">
    <xsl:text>ID,seq,Date,quantity&#10;</xsl:text>
    <xsl:for-each-group select="Record" composite="yes" group-by="ID, date">
        <xsl:apply-templates select="current-group()"/>
    </xsl:for-each-group>
  </xsl:template>

  <xsl:template match="Record">
      <xsl:value-of select="ID, position(), date, quantity" separator=","/>
      <xsl:text>&#10;</xsl:text>
  </xsl:template>

</xsl:stylesheet>