[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: transformation of groups of siblings

Subject: RE: transformation of groups of siblings
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Fri, 23 May 2003 14:47:59 -0500
xsl treenode
> So again, the question is: Is there an XPath expression that 
> would allow
> me to select and transform sibling group 1, followed by 
> sibling group 2,
> and then finally group 3 in a generic manner?
> 
> 
> [ After all this explanation, I sure hope the answer isn't completely
> trivial. :) ]

I don't think so.  :-)
However I have been working on something recently where I had groups
that were determined by what came before and after.

How about this:

As in the classic approach to grouping, first select exactly one
representative element of each group and apply a template to it;
and in that template, process all the members of that group.

The representative element of each group can be selected by:

  "/*/TreeNode[TreeNode or not(preceding-sibling::TreeNode[1][not(TreeNode)])]"

In other words, if a /*/TreeNode has TreeNode children, it
contains a group.
Or if a /*/TreeNode isn't immediately preceded by a childless TreeNode,
then it represents a group (it may be either a container TreeNode, or the
first in a group of childless TreeNodes).

So you want to apply-templates to the above select expression.

Then in the template that matches these nodes (e.g. match="TreeNode"
unless you have other templates like that... in which case it's probably
easiest to use a mode="process-group"), check whether the current node
has TreeNode children (test="TreeNode").  If so, it's a container,
so process its children as a group.

If not, process it and its following siblings as a group.  In my experience,
this is hard to do efficiently unless you use recursion.  A non-recursive
way would be to use a key that numbers the groups... but the only way I
can think of to do that would be to have the key expression traverse backward
from every /*/TreeNode looking at the grouping properties of all previous
/*/TreeNode's (unless keys are allowed to be recursive?  That would help!)

Anyway, a recursive solution for consecutive childless TreeNode's would
be a template that processes the current TreeNode, and if the following
one is also childless, recurse on it.  Otherwise do nothing.
That way, when you come to the end of the group, the template stops
processing and doesn't pick up the childless TreeNode's that come after
the next container TreeNode.

Hope this helps.
If you need more detail let me know.

Lars


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.