xsl-list
[Top] [All Lists]

transformation of groups of siblings

2003-05-23 09:39:00

Is there an XPath expression that would allow me to select and transform
sibling group 1, followed by sibling group 2, then group 3, etc. in the
XML below?  I'm thinking along the lines of a combination of axes and
predicates, but the necessary black magic hasn't fallen out of my
incantations yet...

  <TreeNode label="top">

    <TreeNode label="sibling group 1 - item A"/>
    <TreeNode label="sibling group 1 - item B"/>
    <TreeNode label="sibling group 1 - item C"/>

    <TreeNode label="sibling group 2">
      <TreeNode label="child 1"/>
      <TreeNode label="child 2"/>
      <TreeNode label="child 3"/>
    </TreeNode>

    <TreeNode label="sibling group 3 - item A"/>

    <TreeNode label="sibling group 4">
      <TreeNode label="child 1"/>
      <TreeNode label="child 2"/>
    </TreeNode>

    <TreeNode label="sibling group 5">
      <TreeNode label="child 1"/>
      <TreeNode label="child 2"/>
    </TreeNode>

    <TreeNode label="sibling group 6 - item A"/>
    <TreeNode label="sibling group 6 - item B"/>

  </TreeNode>


Notes:

1) The XML structure is recursive and my preference is to keep it that
way.  If I can't keep the recursion, I have a processing alternative
that I would choose over losing the recursion.  See note 6 below.

2) The number of items in each group is unknown until the transform is
executed.

3) The number of groups is unknown until the transform is executed. 
Basically groups are determined by consecutive elements with no children
interspersed with one or more elements with children.  Each element with
children is a group to be processed separately, but I believe that
detail is the simplest of the issues here.

4) If necessary, additional XSLT can be used, e.g. a "for-each"
instruction, but I'm not sure how that would help.  Recursion might be
useful...

5) Additional XML can *not* be used.

6) My alternative XPath with the problem being that when processing the
root element it selects all elements without children both before and
after the one with children:

        TreeNode[ count(TreeNode) <= 0 ]


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. :) ]


-- 
Steve Rosenberry
Sr. Partner

Electronic Solutions Company -- For the Home of Integration
http://ElectronicSolutionsCo.com

(610) 670-1710

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



<Prev in Thread] Current Thread [Next in Thread>