[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XPath for expressing contiguous elements?

Subject: Re: XPath for expressing contiguous elements?
From: "Syd Bauman s.bauman@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 1 May 2017 13:13:41 -0000
Re:  XPath for expressing contiguous elements?
Roger --

I'm just wondering if this isn't the wrong tool for the job.

 element Test { B*, A*, B* }

While non-deterministic, does ensure that all As are contiguous.
(And, if at least one A is required, i.e. "A+" instead of "A*", then
it is deterministic.)


But if what you really want is a simple Schematron test, then

| <sch:rule context="A">
|   <sch:report test="following-sibling::B[following-sibling::A]">oops</sch:report>
| </sch:rule>

has the advantage of simplicity, but the disadvantage that it will
fire multiple times (twice for your example) rather than just once.
You can reduce the number of times that it fires with

|   <sch:report test="following-sibling::*[1][self::B][following-sibling::A]">oops</sch:report>

but that still doesn't guarantee it is only fired once, and has lost
a good chunk of the simplicity.



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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.