【发布时间】:2019-07-25 13:56:14
【问题描述】:
我有以下两个 xml 文件。 文件 A:
<breakfast_menu>
<food>
<id>1</id>
<name>Belgian Waffles</name>
<price>$5.95</price>
<calories>650</calories>
</food>
<food>
<id>2</id>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<calories>900</calories>
</food>
</breakfast_menu>
和文件 B:
<breakfast_menu>
<food>
<id>1</id>
<description>here we have already a description element</description>
<otherData>s3650</otherData>
</food>
<food>
<id>2</id>
<otherData>s3250</otherData>
<otherData2>g508</otherData2>
<otherData3>sidi6098</otherData3>
</food>
</breakfast_menu>
我无法实现的是,对于基于记录 id 匹配的每条记录,从名为 A 的 xml 文件中获取所有信息,并将所有这些信息放在文件 B 的描述元素中,但也要保留它来的元素从。如果匹配的记录没有描述元素,我们添加一个。如果它已经有一个,那么我们必须知道从文件 A 中获取的信息从哪里开始,带有一个文本分隔符,即“-followingInfoTakenFromFileA-”。因此,考虑到上述情况,所需的输出应该是:
<breakfast_menu>
<food>
<id>1</id>
<description>here we have already a description element-followingInfoTakenFromFileA-name:Belgian Waffles-price:$5.95-calories:650</description>
<otherData>s3650</otherData>
</food>
<food>
<id>2</id>
<otherData>s3250</otherData>
<otherData2>g508</otherData2>
<otherData3>sidi6098</otherData3>
<description>name:Strawberry Belgian Waffles-price:$7.95-calories:900</description>
</food>
</breakfast_menu>
【问题讨论】:
-
好吧,既然您已将问题标记为xslt-3.0 并在您的问题中使用了“合并”一词,那么您是否研究过XSLT 3 的特性,例如合并w3.org/TR/xslt-30/#merging?看起来您应该能够为您的样本提出一些方法,至少可以准确地向我们展示您遇到的问题。
-
是的,我尝试过使用 xsl:merge,并且我有一个输出,其中包含许多描述元素。我只需要一个,使用上面显示的输出中描述的分隔符,我使用 saxon java 9.9 HE。我的努力类似于此处显示的示例:w3.org/TR/xslt-30/#merging
-
请编辑您的问题并向我们展示您的 XSLT 代码及其给出的结果。
-
我现在的代码不起作用,因此我根本无法得到任何结果,有点搞砸了:(
标签: xslt-3.0