xsl 1.0 用逗号分隔的项目进行分组
类似的 XML
<profiles>
<profile>
<customer>customer a </customer>
<collateral>
<summary>summary a</summary>
<related>
<solutions>sol1,sol2</solutions>
</related>
<collateral>
</profile>
<profile>
<customer>customer b </customer>
<collateral>
<summary>summary b</summary>
<related>
<solutions>sol1</solutions>
</related>
<collateral>
</profile>
<profile>
<customer>customer c </customer>
<collateral>
<summary>summary c</summary>
<related>
<solutions>sol2,sol3</solutions>
</related>
<collateral>
</profile>
</profiles>
我有一个与此所需输出
<div id="#sol1">
customer a,summary a
customer b, summary b
</div>
<div id="#sol2">
customer a,summary a
customer c,summary c
</div>
......
我知道 Muenchian 的分组方式,但不确定如果我有逗号分隔的 groub-by 元素值,我该如何完成。任何帮助将不胜感激。
I have a XML similar to this
<profiles>
<profile>
<customer>customer a </customer>
<collateral>
<summary>summary a</summary>
<related>
<solutions>sol1,sol2</solutions>
</related>
<collateral>
</profile>
<profile>
<customer>customer b </customer>
<collateral>
<summary>summary b</summary>
<related>
<solutions>sol1</solutions>
</related>
<collateral>
</profile>
<profile>
<customer>customer c </customer>
<collateral>
<summary>summary c</summary>
<related>
<solutions>sol2,sol3</solutions>
</related>
<collateral>
</profile>
</profiles>
Desired output
<div id="#sol1">
customer a,summary a
customer b, summary b
</div>
<div id="#sol2">
customer a,summary a
customer c,summary c
</div>
..............
Iam aware of Muenchian way of grouping, but not sure how I can accomplish, if I have comma separated groub-by element values. Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然这在 XSLT 2.0 中很简单,但在 XSLT 中,两遍转换可以产生所需的结果:
当此转换应用于提供的 XML 文档时(针对格式良好):
产生了想要的正确结果:
解释:
我们分两遍进行转换。 Pass2 应用于对所提供的 XML 文档应用 Pass1 的结果。
Pass 1 本质上是为任何
solutions
元素覆盖的身份规则。solutions
元素的处理包括对其字符串值的递归分割。 Pass1 的最终结果如下:--
.3。然后,我们对 Pass1 的结果应用模板(在
mode="pass2"
中)。这是典型的传统慕尼黑团体。While this is straight-forward in XSLT 2.0, in XSLT a two-pass transformation can produce the wanted results:
when this transformation is applied on the provided XML document (corrected for well-formedness):
the wanted, correct result is produced:
Explanation:
We carry out the transformation in two passes. Pass2 is applied on the result of applying Pass1 on the provided XML document.
Pass 1 is essentially the identity rule overriden for any
solutions
element. The processing of asolutions
element consists in recursive splitting of its string value. The final result of Pass1 is the following:--
.3. We then apply templates (in
mode="pass2"
) on the result of Pass1. This is a typical and traditional Muenchian grouping.