[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: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 1 May 2017 14:09:26 -0000
Re:  XPath for expressing contiguous elements?
On Mon, May 01, 2017 at 12:59:57PM -0000, Costello, Roger L. costello@xxxxxxxxx scripsit:
> Hi Folks,
> 
> I want an XPath expression that implements this rule:
> 
> 	All <A> elements shall be contiguous within <Test>.

I think it's easier to think of this as "is there something between
A's?" than trying to think of it as "are all the A's continguous?"

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs" version="2.0">
    <xsl:variable name="testYes">
        <Test>
            <B />
            <A />
            <A />
            <A />
            <B />
        </Test>
    </xsl:variable>
    <xsl:variable name="testNo">
        <Test>
            <B />
            <A />
            <A />
            <B />
            <A />
            <B />
        </Test>
    </xsl:variable>
    <xsl:variable name="testShort">
        <Test>
            <B />
            <A />
            <B />
        </Test>
    </xsl:variable>
    <xsl:template match="/">
        <xsl:sequence select="not(($testYes/Test[A[2]]/*[not(self::A)][preceding-sibling::A and following-sibling::A]))" />
        <xsl:sequence select="not(($testNo/Test[A[2]]/*[not(self::A)][preceding-sibling::A and following-sibling::A]))" />
        <xsl:sequence select="not(($testShort/Test[A[2]]/*[not(self::A)][preceding-sibling::A and following-sibling::A]))" />
    </xsl:template>
</xsl:stylesheet>

The above returns "true, false, true".  It doesn't assume that there are
necessarily multiple A children of Test.  I don't know if you want to
define one A child as contiguous or not; the above would say it is.

-- Graydon

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.