[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|