Subject: Re: [xsl] XPath for expressing contiguous elements? From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 1 May 2017 14:09:26 -0000 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XPath for expressing cont, Imsieke, Gerrit, le- | Thread | Re: [xsl] XPath for expressing cont, Michael Kay mike@xxx |
Re: [xsl] XPath for expressing cont, Imsieke, Gerrit, le- | Date | Re: [xsl] XPath for expressing cont, Michael Kay mike@xxx |
Month |