xsl-list
[Top] [All Lists]

RE: [xsl] Constructing a tree from leaf nodes (knowing the tree structure)?

2007-04-19 22:47:58
Hi Ragulf :-),

Pls see >>> below

Regards, Simon

-----Original Message-----
From: Ragulf Pickaxe [mailto:ragulf(_dot_)pickaxe(_at_)gmail(_dot_)com] 
Sent: April 19, 2007 10:23 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Constructing a tree from leaf nodes (knowing the tree
structure)?

Hi Simon,

I am on my way out of the door, but I just want to know if I have
understood correctly - and if I have, this might make it easier for
others to find a solution.

From what I gather, in your example, you have elements c and d in your
data file. Because they are defined, and are the only children of
element b, @result in b can also be calculated (false AND true gives
false, so <b result="false ..>).
correct

Element g contains h and i only, which are defined (result="true" in
both giving g's result attribute a value of true).
correct

c,d,h,i are defined in the data.xml and therefore @complete="true".
Also they are the only childs of elements b and g, which means that b
and g are also complete.
correct

The element f is not defined in the data.xml file, and it does not
have any children that are defined in the file. Therefore @result is
undefined (result=""). Nor is it complete (complete="false").
correct - in this case the value of @result is not significant to me
because @complete="false".

Element e contains both f and g. It seems you do not AND result values
that are NULL (empty string), so e's attribute result="true". But
complete="false" because that is the value of f's complete attribute.
correct - I made the decision that even if @complete="false", as long as
all descendants that have @complete="true" also have @result="true", then
the current node's @result value would be "true"

a contains b and e. Because @result is true in e but false in b and
visa versa for @complete, these attributes both become false in the
element a.
correct

Have I understood your problem?
very well, thank you - I tried to include all possible scenarios in as
short an example as possible.


Regards,
Ragulf Pickaxe :-)


On 4/20/07, Simon Shutter <simon(_at_)schemax(_dot_)com> wrote:
Dimitre,

I believe I do know what the problem is and I'm sorry I've been unable to
communicate it clearly enough in my previous posts.

Let me try again.

I have a known tree structure.  Let's say it's stored in a file tree.xml.
It looks like this:

<a>
  <b>
    <c/>
    <d/>
  </b>
  <e>
    <f/>
    <g>
      <h/>
      <i/>
    </g>
  </e>
</a>

I have an application that generates boolean values (stored in an
attribute
called "result") for a number of data elements.  The element names
correspond to the leaf node elements in the tree structure above.  Let's
say
they are are stored in a file data.xml that looks like this:

<data>
 <c result="true"/>
 <d result="false"/>
 <h result="true"/>
 <i result="true"/>
</data>

Data.xml does not have to contain an element for each leaf node in the
tree.xml.

I am interested in constructing an output tree that has the same structure
as the tree above based only on the leaf node data.  To prevent ambiguity
there can only be one instance of each element in tree.xml.

The idea is that if all descendants of a node have a result attribute =
"true" then the result attribute value of that node is true also.  Ken
identified this in his opening paragraph even though I didn't make it
clear.

In addition to the logical AND calculation, I also want to indicate where
leaf nodes are missing and that is where the "complete" attribute comes
in.
So the output tree should indicate nodes that have missing descendants as
well as the logical AND result.  In the example I used, the desired output
tree is:

<a complete="false" result="false">
 <b complete="true" result="false">
   <c complete="true" result="true"/>
   <d complete="true" result="false"/>
 </b>
 <e complete="false" result="true">
   <f complete="false" result=""/>
   <g complete="true" result="true"/>
     <h complete="true" result="true"/>
     <i complete="true" result="true"/>
   </g>
 </e>
</a>

So in answer to your question, the element f can be absent from data.xml
but
it needs to be in the output tree so it can identified as missing when the
output tree is transformed to HTML.  That is why all the leaf nodes have a
"complete" attribute.

Perhaps it is my choice of attributes that has caused confusion here.
Anyhow, I hope that this attempt to outline my requirements makes more
sense
than the original post.

Regards, Simon

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--