On Mon, May 01, 2017 at 12:59:57PM -0000, Costello, Roger L.
costello(_at_)mitre(_dot_)org 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
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--