XSLT 2.0 中的分组(按文本分组)

Grouping in XSLT 2.0 (grouping by text)

我在 xslt 中找出这个分组时遇到问题:

初始信息:

<Application>

  <ApplicationItem LayoutPath="Attachments.Package.Attachment[bfd0b74d-2888-49d9-a986-df807f08ad8a].UniqueID" Value="bfd0b74d-2888-49d9-a986-df807f08ad8a" />
  <ApplicationItem LayoutPath="Attachments.Package.Attachment[bfd0b74d-2888-49d9-a986-df807f08ad8a].Filename" Value="Document 1 Test" />
  <ApplicationItem LayoutPath="Attachments.Package.Attachment[bfd0b74d-2888-49d9-a986-df807f08ad8a].URI" Value="https/.test.pdf" />

  <ApplicationItem LayoutPath="Attachments.Package.Attachment[bfd0b74d-2888-49d9-a986-df807f08ad8b].UniqueID" Value="bfd0b74d-2888-49d9-a986-df807f08ad8b" />
  <ApplicationItem LayoutPath="Attachments.Package.Attachment[bfd0b74d-2888-49d9-a986-df807f08ad8b].Filename" Value="Document 2 Test" />
  <ApplicationItem LayoutPath="Attachments.Package.Attachment[bfd0b74d-2888-49d9-a986-df807f08ad8b].URI" Value="google.com" />

</Application>

预期结果:

<Package>
   <Attachment UniqueID="bfd0b74d-2888-49d9-a986-df807f08ad8a"
      Filename="Document 1 Test"
      URI="https/.test.pdf"/>
   <Attachment UniqueID="bfd0b74d-2888-49d9-a986-df807f08ad8b"
      Filename="Document 2 Test"
      URI="google.com"/>
<Package>

我的代码: 我已经使用方括号中的 id 完成了分组。

<xsl:for-each-group select="ApplicationItem[contains(@LayoutPath,'Attachments.Package.Attachment')]" group-by="substring-before(substring-after(@LayoutPath, 'Attachments.Package.Attachment['), ']')">
            <Attachment>
                <xsl:for-each select="current-group()">
                    <xsl:attribute name="UniqueID" select="current-grouping-key()"/>
                    <xsl:attribute name="Filename" select=".[contains(@LayoutPath,'Filename')]/@Value"/>
                    <xsl:attribute name="URI" select=".[contains(@LayoutPath,'URI')]/@Value"/>
                </xsl:for-each>
            <Attachment>
</xsl:for-each-group>

我的结果:

<Package>
   <Attachment UniqueID="bfd0b74d-2888-49d9-a986-df807f08ad8a"
      Filename=""
      URI="https/.test.pdf"/>
   <Attachment UniqueID="bfd0b74d-2888-49d9-a986-df807f08ad8b"
      Filename=""
      URI="google.com"/>
<Package>

我需要更改代码以使用分组,因为目前无法仅使用具有唯一 @LayoutPath 的最后一个 ApplicationItem。 我认为问题出在分组上,但现在不知道如何解决它。

删除 <xsl:for-each select="current-group()"> 并更改

                <xsl:attribute name="Filename" select=".[contains(@LayoutPath,'Filename')]/@Value"/>
                <xsl:attribute name="URI" select=".[contains(@LayoutPath,'URI')]/@Value"/>

                <xsl:attribute name="Filename" select="current-group()[contains(@LayoutPath,'Filename')]/@Value"/>
                <xsl:attribute name="URI" select="current-group()[contains(@LayoutPath,'URI')]/@Value"/>