[xsl] slicing an XML document

Subject: [xsl] slicing an XML document
From: Saverio Perugini <sperugin@xxxxxxxxxxxxxxxx>
Date: Tue, 15 Oct 2002 13:15:53 -0400 (EDT)
Hello,

Is it possible to slice an XML tree into levels?
In other words, parameterize a stylesheet by level number and
return all tags or name()'s corresponding to that level.

Consider the following XML:

<db>
   <small>
      <olives>
         <thin/>
      </olives>
      <onions>
         <thin/>
         <thick/>
      </onions>
   </small>
   <med>
      <onions>
         <pan/>
         <thin/>
      </onions>
      <peppers>
         <crispy/>
         <thick/>
      </peppers>
   </med>
   <large>
      <peppers>
         <pan/>
         <thin/>
      </peppers>
      <ham>
         <crispy/>
         <thick/>
      </ham>
   </large>
</db>

Imagine that the leaves correspond to a pizza order and the levels correspond to
size, topping, and crust, in that order.

If I'd like a list of all possible sizes then I want to slice the tree at the
first level; and desire the following output.

small, med, large

If I'd like a list of all possible toppings, then I want to slice the tree at the
second level; and desire the following output.

olives, onions, peppers, ham

And lastly, if I'd like a list of all possible crusts, then I want to slice the tree
at the third level; and desire the following output.

thin, thick, pan, crispy

Is there a quick and dirty way to slice an XML document?

Thank You and Best Regards,

S. Perugini


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


Current Thread