【发布时间】:2012-05-01 22:21:29
【问题描述】:
我正在处理 XSLT 转换。我有一个源文件,其中有一些名为 tag 的标签。
认为我的源 xml 是这样的。
<ABC>
<Name>Some Name </Name>
<ID>Some ID</ID>
<Address>Some Address</Address>
<Place>Some Place</Place>
<ID>Some ID</ID>
<Name>Some Name </Name>
<Name>Some Name </Name>
</ABC>
规则:
ABC is parent Tag which has 4 child tags. Name, ID, Address, Place.
These child tags can occur many times and in any ordrer.
Upon reading the tag , I want to change the name of the tag, and do some processing on the value present in the tag.
The input XML may have child tags in any order, and many times.
I want to write a common XSLT which will read the child tags in the order in which they occur, and display them as given under.
我想这样显示输出。
<Frame:Name>
<text>Some Name</text>
</Frame:Name>
<Frame:ID>
<text>Some ID</text>
</Frame:ID>
<Frame:ADdrress>
<text>Some Address</text>
</Frame:Address>
<Frame:Place>
<text>Some Place</text>
</Frame:Place>
<Frame:ID>
<text>Some ID</text>
</Frame:ID>
<Frame:Name>
<text>Some Name</text>
</Frame:Name>
<Frame:Name>
<text>Some Name</text>
</Frame:Name>
我完全震惊了它是如何做到的。
如果源 XML 中子元素的出现顺序发生变化,它也应该反映在输出 XML 中。
有人可以分享评论吗?
谢谢。
【问题讨论】:
-
你能分享你的 XSLT 代码吗?如果它看起来不错,那么我们可以根据您的要求进行修改。我们可以设计新代码,但如果您发布代码,您就可以知道自己的错误
-
在想要的结果中,您错过了最后一个
Name元素。请正确。
标签: xml xslt xpath xslt-grouping