Subject: Re: [xsl] XPath expression to check that there are no intervening elements? From: "G. Ken Holman g.ken.holman@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 19 Jul 2016 16:16:28 -0000 |
count(B[last()]/preceding-sibling::*[not(self::B)]) = count(B[1]/preceding-sibling::*[not(self::B)])
string( generate-id( B[1]/preceding-sibling::*[not(self::B)][1] ) ) = string( generate-id( B[last()]/preceding-sibling::*[not(self::B)][1] ) )
Hi Folks,
This XML has a solid block of <B> elements:
<Document> <A/> <B/> <B/> </Document>
This XML has an intervening <C> element:
<Document> <A/> <B/> <C/> <B/> </Document>
I need an XPath expression to return a Boolean value:
Return true if there is one solid block of <B> elements (no intervening elements). Otherwise, return false.
I created a horrendous XPath expression to solve it:
count(B) eq (B[last()]/count(preceding-sibling::*)+1 - B[1]/count(preceding-sibling::*))
Can you provide a better (simpler, more efficient) XPath expression?
/Roger
-- Check our site for free XML, XSLT, XSL-FO and UBL developer resources | Streaming hands-on XSLT/XPath 2 training @US$45: http://goo.gl/Dd9qBK | Crane Softwrights Ltd. _ _ _ _ _ _ http://www.CraneSoftwrights.com/s/ | G Ken Holman _ _ _ _ _ _ _ _ _ _ mailto:gkholman@xxxxxxxxxxxxxxxxxxxx | Google+ blog _ _ _ _ _ http://plus.google.com/+GKenHolman-Crane/posts | Legal business disclaimers: _ _ http://www.CraneSoftwrights.com/legal |
--- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XPath expression to check, Michael Kay mike@xxx | Thread | Re: [xsl] XPath expression to check, Dimitre Novatchev dn |
Re: [xsl] XPath expression to check, Michael Kay mike@xxx | Date | Re: [xsl] XPath expression to check, Dimitre Novatchev dn |
Month |