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

时间:2016-11-25 16:06:39

标签: xpath xslt-2.0

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

初始信息:

final static allPeople List<Person> = new ArrayList<Person>();

预期结果:

...
if (allPeople.contains(aPerson)){
...

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

<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>

我需要在代码中更改以使用分组,因为现在不能使用唯一的@LayoutPath的最后一个ApplicationItem。 我认为问题在于分组,但现在不知道如何修复它。

1 个答案:

答案 0 :(得分:1)

删除<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"/>