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.
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
solutionselement. The processing of asolutionselement 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.