【发布时间】:2010-05-18 10:45:48
【问题描述】:
我有一个如下组织的 XML-
<section name="Parent 1 Text here" ID="1" >
<section name="Child 1 Text here" ID="11">
</section>
<section name="Child 2 Text here" ID="12">
<section name="GrandChild Text here" ID="121" >
</section>
</section>
</section>
<section name="Parent 2 Text here" ID="2" >
<section name="Child 1 Text here" ID="22">
</section>
<section name="Child 2 Text here" ID="23">
<section name="GrandChild Text here" ID="232" >
</section>
</section>
</section>
我必须生成以下输出 XML -
<section name="Parent 1 Text here" ID="1" >
<section name="Child 2 Text here" ID="12">
<section name="GrandChild Text here" ID="121" >
</section>
</section>
</section>
<section name="Parent 2 Text here" ID="2" >
<section name="Child 2 Text here" ID="23">
</section>
</section>
我必须使用 XSLT 1.0 转换来实现上述目标。我打算将逗号分隔的字符串作为参数传递,其值 = "1,12,121,2,23"
我的问题-如何在 XSLT 1.0 中循环逗号分隔的参数? 有没有更简单的方法来实现上述目标。请记住我必须在 XSLT 1.0 中执行此操作 感谢您的帮助。
【问题讨论】:
-
您能否进一步扩展您的约束条件?我推断您想为每个选定的孩子输出一个嵌套结构,其中包括该孩子的所有祖先。你会想省略一代吗?您是否会遇到为给定父母选择两个或更多后代的情况?如果是这样,您是要输出多个嵌套结构(每个选定的子节点一个),还是一个具有多个后代叶节点的结构?
标签: xslt