On 16/09/2010 11:20 PM, Jesper Tverskov wrote:
I have a question to the list about the "equalizing" step stylesheet
(see tutorial), the step that adds missing optional elements. Is there
a better way to do it? My "equalizing" stylesheet works as follows
(flattening has already taken place):
It's difficult to tell whether there's a better way of doing it without
a specification of what you are doing. It's not clear to me what you
want to happen if for example one element has children (a,b,c) and
another has children (c,a,b).
Let's suppose we only want to handle inputs in which all elements have a
sequence of children that is a projection of some sequence S, and the
requirement is to find the minimum sequence S for which this is true.
Here's an approach to solving this.
First, find the set of ordered pairs of adjacent child elements. For
example if the subsequences present are (a,b,c,z) and (a,b,d,z) this is
(ab, bc, cz, bd, dz). Then apply the following algorithm recursively:
1. find a name that has not already been output that does not apear as
the second of a pair of which the first name has not yet been output.
2. output this name
3. repeat until no further names are found
There's an error condition that needs detecting here if there is no
partial ordering.
Translating this into XSLT terms is something I leave as an excercise
for the reader! As often, the challenge is to decide what data structure
to use. I think that for the "set of ordered pairs" I would probably use
two parallel sequences of xs:QName values.
To allow for repeating elements, perhaps (a,b,c,c,d) should be renamed
as (a1,b1,c1,c2,d1).
Michael Kay
Saxonica
--~------------------------------------------------------------------
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>
--~--