Re: [xsl] XPath for expressing contiguous elements?

Subject: Re: [xsl] XPath for expressing contiguous elements?
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 1 May 2017 20:00:30 -0000
> And here is an XPath 2.0 expression:
>
> empty(/*/B[. >> /*/A[1] and /*/A[last()] >> .])

Making this more general:

       empty(/*/*[not(self::A)][. >> /*/A[1] and /*/A[last()] >> .])


This XPath expression happens to be slightly shorter (by 3 characters)
than the XPath 1.0 expression suggested by Dr. Michael Kay:

     not(*[not(self::A)][following-sibling::A][preceding-sibling::A])



Cheers,
Dimitre



On Mon, May 1, 2017 at 11:42 AM, Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
> And here is an XPath 2.0 expression:
>
> empty(/*/B[. >> /*/A[1] and /*/A[last()] >> .])
>
>
>
>
> On Mon, May 1, 2017 at 5:59 AM, Costello, Roger L. costello@xxxxxxxxx
> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>> Hi Folks,
>>
>> I want an XPath expression that implements this rule:
>>
>>         All <A> elements shall be contiguous within <Test>.
>>
>> In this example all A's are contiguous, so the rule is satisfied:
>>
>> <Test>
>>     <B/>
>>     <A/>
>>     <A/>
>>     <A/>
>>     <B/>
>> </Test>
>>
>> In this example there is an intervening B, so the rule is not satisfied:
>>
>> <Test>
>>     <B/>
>>     <A/>
>>     <A/>
>>     <B/>
>>     <A/>
>>     <B/>
>> </Test>
>>
>> Below is the XPath that I created. I have two questions about it:
>>
>> (1) Is it correct? Do you see anything it would fail to catch?
>>
>> (2) Is there a better (simpler, more efficient) XPath expression?
>>
>> Here is the XPath (within a Schematron rule):
>>
>> <sch:rule context="Test">
>>     <sch:assert test="
>>         every $i in A satisfies
>>            (if ($i/preceding-sibling::A) then $i/preceding-sibling::*[1][self::A] else true())
>>            and
>>            (if ($i/following-sibling::A) then $i/following-sibling::*[1][self::A] else true())
>>         ">
>>         All A's shall be contiguous within Test.
>>     </sch:assert>
>> </sch:rule>
>> 
>
>
>
> --
> Cheers,
> Dimitre Novatchev
> ---------------------------------------
> Truly great madness cannot be achieved without significant intelligence.
> ---------------------------------------
> To invent, you need a good imagination and a pile of junk
> -------------------------------------
> Never fight an inanimate object
> -------------------------------------
> To avoid situations in which you might make mistakes may be the
> biggest mistake of all
> ------------------------------------
> Quality means doing it right when no one is looking.
> -------------------------------------
> You've achieved success in your field when you don't know whether what
> you're doing is work or play
> -------------------------------------
> To achieve the impossible dream, try going to sleep.
> -------------------------------------
> Facts do not cease to exist because they are ignored.
> -------------------------------------
> Typing monkeys will write all Shakespeare's works in 200yrs.Will they
> write all patents, too? :)
> -------------------------------------
> Sanity is madness put to good use.
> -------------------------------------
> I finally figured out the only reason to be alive is to enjoy it.



-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Current Thread