我一直在查看 XSLT 1.0 中的 Muenchian 分组示例,特别是这里的示例。但是我无法让它在更复杂的 XML 结构上工作。
我的 XML 目前看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<ContestResults>
<Contests>
<Contest sportId="35">
<Sport>Beach Volleyball</Sport>
<Event>Men's</Event>
<Ranks>
<Rank position="1" eventId="1">
<Athlete>Athlete 1a / Athlete 2a [GER]</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="1">
<Athlete>Athlete 1b / Athlete 2b [NED]</Athlete>
<Result>0</Result>
</Rank>
</Ranks>
</Contest>
<Contest sportId="32">
<Sport>Tennis</Sport>
<Event>Women's Singles</Event>
<Ranks>
<Rank position="1" eventId="2">
<Athlete>Tennis Athlete 1</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="2">
<Athlete>Tennis Athlete 2</Athlete>
<Result>1</Result>
</Rank>
</Ranks>
</Contest>
<Contest sportId="35">
<Sport>Beach Volleyball</Sport>
<Event>Men's</Event>
<Ranks>
<Rank position="1" eventId="3">
<Athlete>Athlete 3a / Athlete 4a [AUT]</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="3">
<Athlete>Athlete 3b / Athlete 4b [SUI]</Athlete>
<Result>0</Result>
</Rank>
</Ranks>
</Contest>
</Contests>
</ContestResults>
但是,当它们具有相同的 Sport 和 Event 时,我想将 Rank 节点分组到相同的 Ranks 父级下。所以我希望结果看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<ContestResults>
<Contests>
<Contest sportId="35">
<Sport>Beach Volleyball</Sport>
<Event>Men's</Event>
<Ranks>
<Rank position="1" eventId="1">
<Athlete>Athlete 1a / Athlete 2a [GER]</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="1">
<Athlete>Athlete 1b / Athlete 2b [NED]</Athlete>
<Result>0</Result>
</Rank>
<Rank position="1" eventId="3">
<Athlete>Athlete 3a / Athlete 4a [AUT]</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="3">
<Athlete>Athlete 3b / Athlete 4b [SUI]</Athlete>
<Result>0</Result>
</Rank>
</Ranks>
</Contest>
<Contest sportId="32">
<Sport>Tennis</Sport>
<Event>Women's Singles</Event>
<Ranks>
<Rank position="1" eventId="2">
<Athlete>Tennis Athlete 1</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="2">
<Athlete>Tennis Athlete 2</Athlete>
<Result>1</Result>
</Rank>
</Ranks>
</Contest>
</Contests>
</ContestResults>
我只是有点迷失如何做到这一点,因为唯一的其他例子是处理一个更简单的结构,我不确定它是否可能或者我的密钥和模板需要如何构建才能做到这一点。谁能提供一些示例如何实现?
任何意见,将不胜感激。