Subject: Re: [xsl] Is the first preceding-sibling a processing-instruction? From: "Eliot Kimber eliot.kimber@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 8 May 2023 17:45:46 -0000 |
I find these kind of nearest preceding thing that is a kind of thing but not other things and theres no other thing intervening checks to be one of the most challenging to express in XPath, certainly in any kind of compact XPath. I often solve them by selecting an anchoring element that the check can be relative to using << or >>, i.e., find the nearest preceding thing that the target cant be before, then use that as the boundary for finding the thing you want, i.e.: <xsl:variable name=preceding-element select=preceding::*[1]/> <xsl:variable name=preceding-pi select=preceding::processing-instruction()[. >> $preceding-element][1]/> I suppose the first variable could be put inline in the second XPath, but in an XSLT context I find it clearer to separate out the anchoring node. Its certainly easier to test and debug. Cheers, E. _____________________________________________ Eliot Kimber Sr Staff Content Engineer O: 512 554 9368 M: 512 554 9368 servicenow.com<https://www.servicenow.com> LinkedIn<https://www.linkedin.com/company/servicenow> | Twitter<https://twitter.com/servicenow> | YouTube<https://www.youtube.com/user/servicenowinc> | Facebook<https://www.facebook.com/servicenow> From: Piez, Wendell A. (Fed) wendell.piez@xxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Monday, May 8, 2023 at 11:54 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Subject: Re: [xsl] Is the first preceding-sibling a processing-instruction? [External Email] ________________________________ How about preceding-sibling::processing-instruction() except preceding-sibling::node()/preceding-sibling::processing-instruction() ? Presumably this should get any PI that is immediately behind the context node, but none that are not. (Untested.) Cheers, Wendell From: Eliot Kimber eliot.kimber@xxxxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Sent: Monday, May 8, 2023 11:31 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] Is the first preceding-sibling a processing-instruction? I interpreted the initial requirement as If the first preceding sibling that is not an empty text() node is a processing instruction, get that. But the markup as shown as the starting point only has elements, PIs, and text nodes, so for that content a simple preceding-sibling::processing-instruction()[1] would give the right answer, assuming there is always a PI before each element. Cheers, E. _____________________________________________ Eliot Kimber Sr Staff Content Engineer O: 512 554 9368 M: 512 554 9368 servicenow.com<https://www.servicenow.com/> LinkedIn<https://www.linkedin.com/company/servicenow> | Twitter<https://twitter.com/servicenow> | YouTube<https://www.youtube.com/user/servicenowinc> | Facebook<https://www.facebook.com/servicenow> From: Graydon graydon@xxxxxxxxx<mailto:graydon@xxxxxxxxx> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx rytech.com>> Date: Monday, May 8, 2023 at 10:02 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list@xxxxxxxxxxxxxxxxxxxxxx> <xsl-list@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list@xxxxxxxxxxxxxxxxxxxxxx>> Subject: Re: [xsl] Is the first preceding-sibling a processing-instruction? [External Email] On Mon, May 08, 2023 at 01:37:45PM -0000, Michael Kay mike@xxxxxxxxxxxx<mailto:mike@xxxxxxxxxxxx> scripsit: > But you could do > > preceding-sibling::node()[not(self::text())][1][self::processing-instruction( )] I would use preceding-sibling::processing-instruction()[1] And I think it means "of my preceding siblings nodes which have node type processing instruction, I want the one closest to me". Have I got that wrong? Or is it only wanted if there's no intervening node that's not a white space only text node? -- Graydon Saunders | graydonish@xxxxxxxxx<mailto:graydonish@xxxxxxxxx> ^fs oferiode, pisses swa mfg. -- Deor ("That passed, so may this.") XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list> EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/3302254> (by email) XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list> EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/3453418> (by email<>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Is the first preceding-si, Piez, Wendell A. (Fe | Thread | [xsl] today I learned <xsl:next-mat, Chris Papademetrious |
Re: [xsl] Is the first preceding-si, Piez, Wendell A. (Fe | Date | [xsl] today I learned <xsl:next-mat, Chris Papademetrious |
Month |