【发布时间】:2012-07-11 06:00:33
【问题描述】:
我需要合并两个节点 street 因为它们是相同的:
- 父节点:纽约市
- 方法相同:修改
- 相同的ID:0
必须合并属性值(请参阅本文末尾的输出文件)
这是输入文件:
<country>
<state id="NEW JERSEY">
<city id="NEW YORK">
<district id="BRONX" method="modify">
<street id="0" method="modify">
<attributes>
<temperature>98</temperature>
<altitude>1300</altitude>
</attributes>
</street>
<dadada id="99" method="modify" />
<street id="0" method="modify">
<attributes>
<temperature>80</temperature>
<streetnumber> 67 </streetnumber>
</attributes>
</street>
<dididi id="432" method="modify" />
</district>
</city>
</state>
预期输出:
<country>
<state id="NEW JERSEY">
<city id="NEW YORK">
<district id="BRONX" method="modify">
<street id="0" method="modify">
<attributes>
<temperature>80</temperature>
<altitude>1300</altitude>
<streetnumber> 67 </streetnumber>
</attributes>
</street>
<dadada id="99" method="modify" />
<dididi id="432" method="modify" />
</district>
</city>
</state>
</country>
请帮忙,我刚刚开始 XSLT
【问题讨论】:
-
两次发布本质上相同的问题并不能增加您在 SO 上获得问题的好答案的机会。 how to merge two nodes having "the same father" and adequate method (using XSLT)? 的可能重复项
-
这些问题(略有)不同,尽管它们看起来非常相似。输入文件格式肯定不同。另一个问题对方法有条件(CREATE then MODIFY and id = "MANHATTAN")。这里是方法 (MODIFY + MODIFY) 和 id="0" (number)
-
@laurentngu:事实上,你(我怀疑你和约翰是同一个人)多年来一直在问同一个问题的许多细微变化——这表明你没有从答案,并且您有一个更深层次的问题,很可能是缺乏对 XSLT 的基本了解。我强烈建议您购买一本关于 XSLT 的好书并阅读和学习。继续发布相同的问题并且显然不理解答案显然对您没有任何好处。
-
@dimetre Novatchev 你好,我不是那个人/用户。今晚我一直在寻求有关 xslt 的帮助,因为我尝试从 Perl 转移到 xslt 以对我的 xml 文件进行排序。您提到的那个用户是我个人项目的临时远程参与者/助手。简而言之,我非常渴望学习 xslt 并在未来的项目中传播它。很抱歉我今晚的问题正在回忆其他帖子给您带来的不便,但这是使用和学习 xslt 的意愿
-
@laurentngu:自 2 月以来,我一直看到这个问题略有不同。请不要再问同一个问题的变体——如果你问不同的问题,这是完全可能的,甚至对你的学习更好。
标签: xml xslt xslt-1.0 xslt-2.0 xmlnode