不同节点和元素的 XSLT 1.0 分组键
我正在看慕尼黑分组。我尝试查找与我的 xml 类似的示例,但找不到任何示例。大多数示例结构良好,而我的示例则令人困惑。
这是我的 XML 的缩短版本(请注意,我无法更改 XML 结构,因为它是标准的东西,不由我掌控),我使用的是 XSLT 1,因为系统现在只支持该版本。
<object>
<creator id="123">
<name>ABC</name>
<city>Hamilton</city>
</creator>
<creator><references>456</references></creator>
<contact><references>123</references></contact>
<creator id="456">
<name>XYZ</name>
<city>New York</city>
</creator>
<associatedParty><references>123</references>
<role>Sponsor</role>
</associatedParty>
</object>
我想要的输出是:
<party id="123">
<name>ABC</name>
<city>Hamilton</city>
<role>Creator</role>
<role>Contact</role>
<role>Sponsor</role>
</party>
<party id="456">
<name>XYZ</name>
<city>New York</city>
<role>Creator</role>
<role>Contact</role>
</party>
现在 id 属性被用作引用元素的值。输出中的标记可以是创建者、联系人,或者元素内部的任何内容(如果位于关联方元素下)。
我一直坚持创建密钥来根据 id/references 属性对它们进行分组。据我所知,使用 xsl:key 的示例仅适用于具有相同名称的节点,而我发布的示例具有不同的节点名称。任何帮助将不胜感激!
I am looking at the Muenchian Grouping. I tried finding examples that are similar to my xml but can't find any. Most of the examples are well structured while mine is confusing.
Here's a shortened version of my XML (note that I can't change the XML structure because it's a standard thing and out of my hands), and I'm using XSLT 1 because the system only supports that version now.
<object>
<creator id="123">
<name>ABC</name>
<city>Hamilton</city>
</creator>
<creator><references>456</references></creator>
<contact><references>123</references></contact>
<creator id="456">
<name>XYZ</name>
<city>New York</city>
</creator>
<associatedParty><references>123</references>
<role>Sponsor</role>
</associatedParty>
</object>
The output that I desire is:
<party id="123">
<name>ABC</name>
<city>Hamilton</city>
<role>Creator</role>
<role>Contact</role>
<role>Sponsor</role>
</party>
<party id="456">
<name>XYZ</name>
<city>New York</city>
<role>Creator</role>
<role>Contact</role>
</party>
Now the id attribute is being used as a value for the references element. And the tag in the output can be either creator, contact, or whatever is inside element if it's under an associatedParty element.
I'm stuck with creating the key to group them from their id/references attribute. As far as I see the examples using xsl:key is only for nodes that have the same name, and the example I posted have different node names. Any help would be appreciated!!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此转换:
应用于提供的 XML 文档时:
产生所需的正确结果:
This transformation:
when applied on the provided XML document:
produces the wanted, correct result:
您可以使用此模板:
输出:
You can use this template:
Output: