Re: Wrap changing element sequence into container: wit
It's so much easier if you provide an example, failing that I'll provide one:-)
I apologize for wasting your time by having you guess what I mean instead of giving an example right away. As was to be expected, my longish explanations would mislead you about what I was looking for... So I shamefully promise to get better - here is a realistic example I was able to craft.
input.xml (I left blank lines to emphasize the variations):
<root> <flatsequence> <a>a</a> <b>b</b> <c>c</c> <d>d</d> <e>e</e> <f>f</f>
<h>h</h> <i>i</i> <j>j</j> </flatsequence> <flatsequence> <a>a</a>
<c>c</c> <d>d</d> <e>e</e> <f>f</f> <g>g</g> <h>h</h> <i>i</i> <j>j</j> </flatsequence> </root>
<root> <hierarchy> <a>a</a> <container1> <b>b</b> <c>c</c> </container1> <d>d</d> <e>e</e> <f>f</f> <container2>
<h>h</h> <i>i</i> </container2> <j>j</j> </hierarchy> <hierarchy> <a>a</a> <container1>
<c>c</c> </container1> <d>d</d> <e>e</e> <f>f</f> <container2> <g>g</g> <h>h</h> <i>i</i> </container2> <j>j</j> </hierarchy> </root>
This is, I want to group certain element sequences (of which the first element may be optional) that are occurring within a flat sequence into some container, and group other element sequences within the same flat sequence the same way into other containers, while leaving the rest unchanged. The elements to group, however, are not easily identified formally as their names are dissimilar, so I suppose I will have to spell out their names.
Your last style sheet suggestion was fine. Adapting it to my example lets me create container1 in the case above, but I am stuck as far as creating container2 in the same run is concerned:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template>
<!-- how to match g, h and i as well within the same "for-each-group"? -->
<!-- how to group g, h and i into container2? -->
How to care, in the same pass, for container2 (and a finite number of other containers), which have no "derivable" relation to the elements they are to group?
Do I have to apply some kind of tree-walking or recursion?
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format