|
top
|
Subject: Help! Transform flat XML records to complex grouping structure Author: duncan skelton Date: 16 May 2006 07:36 AM
|
Hi Srinivas
First, thank you for your detailed response - it really set me off in a good direction. Over the weekend Ive progressed very well, and would have something to share with you, and some further questions.
First, I see now where your example code was going, and pursued it so that it generated the output I was looking for. This involved simply nesting further occurrences of the same pattern to sort by 4 levels of containment. (For each component that I have as source it is contained within a module, which is contained within a logicalsubset, within a logicalset within a layer).
But I found a shortcoming with this scheme that I couldn't find an easy solution for. That is the fact that my container IDs are only unique within that level. ie within LayerID=1 I can have a module called 'general', and within LayerID=2 I can have another module called 'general'.
Using the key approach you outline this second occurrence of the 'general' module present in a different layer is not processed, since it will never match the first occurrence of that module within the key.
I experimented and read around using multiple or compound identifiers in the key() function but couldnt understand how to get that to work.
In the meantime then I came across an approach using for-each-group in xslt2.0.
This approach works a treat and is simpler to code and to read.
But I found that I had to code the whole lot in a single template. Ideally I wanted to split the processing of each level of containment into it's own template. That didnt work because I need to act on a node-set, not individual nodes that are passed to a template.
So I looked at user-defined functions - where I could pass a parameter that is a node list, extracted from current-group()
This did the right thing, but I found that for some reason the <xsl:element> and <xsl:attribute> tags within this function were never being output - only the leaf nodes of the component data. I couldnt understand this at all and assume there is some loss of context when calling a function as opposed to keeping everything together inline in a single template.
This is a shame. A couple of the containment levels (logicalset and logicalsubset) are optional. This means I dont want to output elements for these items, and skip straight to the mandatory Module data. This meant using conditional branching and replicating chunks of code.
I think that if I can get the function calls working correctly that the code will be greatly simplified and more readable.
Do you have any ideas of how I could do this, or alternatively why I was seeing the behaviour that I was ?
Ive attached the XSLT2.0 code that I finally got working.
kind regards
duncan. v2transform.xsl Grouping using for-each-group()
|
|
|