xsl-list
[Top] [All Lists]

Re: [xsl] things about grouping

2012-11-29 04:12:20
On Thu, Nov 29, 2012 at 05:58:45AM +0000, Ihe Onwuka scripsit:
Since we're talking about "except" and language definitions, has anyone
ever proposed a different form (or is there a different form for) the
construct:

div[not(* except (heading,para))]

It's really useful, but I find it frequently brain-melting, especially
as a component of more complex expressions.

A problem here is the mixture of notation from mathematical (set
theoretic in the form of except) and non-mathematical (the comma
operator).
[snip]
Now (get ready for the leap of faith and giant hand wave), substitute
the comma operator back for the | and you have div[(heading,para]

All the divs who have heading or para children, yes, but that's not
quite the same thing.

Unless I'm unusually addled this morning,

div[not(* except (heading,para))]

is a div which has _only_ heading or para children

just as

div[* except (heading,para)] is a div with some other element child than
heading and para

So for the trivial markup

<bucket>
    <div>
        <heading>Word</heading>
    </div>
    <div>
        <heading>Word</heading>
        <para>Words</para>
    </div>
    <div>
        <heading>Word</heading>
        <para>Words</para>
        <para>Words</para>
        <figure>Picture</figure>
    </div>
    <div>
        <heading>Word</heading>
        <figure>Picture</figure>
    </div>
</bucket>

//div[(heading,para)] selects all the divs, /bucket/div[1], /bucket/div[2], 
/bucket/div[3], and /bucket/div[4]

//div[not(* except (heading,para))] selects /bucket/div[1] and /bucket/div[2]

//div[* except (heading,para)] selects /bucket/div[3] and /bucket/div[4]

I can imagine a 

//div[only(heading,para)]

//div[not(only(heading,para))]

syntax instead, which I would find much less head-melty, but am not sure it has 
a suitable mathematical justification. (Or would be of sufficiently general 
interest to bother the XPath spec committee about.)

-- Graydon

--~------------------------------------------------------------------
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>
--~--