Re: with XPath 1.0, select all following sibling elements of name "foo" up to the first non-"foo" element
"G. Ken Holman
[email protected]" <
[email protected]>
Thu, 18 Feb 2021 19:37:20 -0000
| Newsgroups |
gmane.text.xml.xsl.general.mulberrytech |
| Message-ID |
<[email protected]> |
self::a:b is namespace-sensitive.
name(.)='a:b' is not namespace-sensitive.
Namespace sensitivity always is preferred.
I hope this helps.
. . . . . . . Ken
At 2021-02-18 18:43 +0000, Wolfhart Totschnig
[email protected] wrote:
>Hello again,
>
>Thank you, Wendell!
>
>The proposed solutions leave me with two questions:
>
>
>1) Is there a way to do what I originally had in
>mind, i.e., go forward to the first non-"foo"
>sibling and from there go backwards, taking all the
>"foo" siblings up to the current node? Asked
>differently, can the following XPath expression be fixed?
>
>following-sibling::*[not(self::source)][1]/preceding-sibling::*[self::source][preceding-sibling::current()]
>
>Specifically, can "preceding-sibling::current()" be fixed?
>
>
>2) Liam's and Wendell's proposals involve the
>expression [name()=...], whereas I have used
>[self:: ...]. Are these strictly equivalent, or
>is there a reason to prefer the one over the other?
>
>
>Thanks again for your help!
>Wolfhart
>
>
>On 18-02-21 13:06, Wendell Piez
><mailto:[email protected]>[email protected] wrote:
>>Hi,
>>
>>With a sequence of variable declarations:
>>
>><xsl:variable name="name" select="name()"/>
>><xsl:variable name="followers" select="following-sibling::*[name()=$name]"/>
>><xsl:variable name="interlopers"
>>select="following-sibling::*[not(name()=$name)]
>>| following-sibling::*[not(name()=$name)]/following-sibling::*"/>
>><xsl:variable name="invited" select=". |
>>$followers[not(count(.|$interlopers)=count($interlopers))]"/>
>>
>>Note: untested.
>>
>>Good luck,
>>Wendell
>>Â Â Â
>>
>>On Wed, Feb 17, 2021 at 8:32 PM Wolfhart
>>Totschnig
>><mailto:[email protected]>[email protected]
>><<mailto:[email protected]>[email protected]>
>>wrote:
>>Dear list,
>>
>>I am facing an XPath problem for which I cannot find the solution. I
>>want to select all following sibling elements of name "foo" up to the
>>first non-"foo" element. So, in the following case, the first two <foo>
>>elements should be selected:
>>
>><foo/>
>><foo/>
>><bar/>
>><foo/>
>>
>>In the following case, all three <foo> elements should be selected:
>>
>><foo/>
>><foo/>
>><foo/>
>>
>>And in the following case, nothing should be selected:
>>
>><bar/>
>><foo/>
>><foo/>
>>
>>I came up with the following non-working approach:
>>
>>Â Â Â Â Â Â Â Â Â Â <xsl:choose>
>>Â Â Â Â Â Â Â Â Â Â Â Â Â <xsl:when
>>test="not(following-sibling::*[not(self::foo)])">
>>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
>>Â <xsl:value-of select="following-sibling::*"/>
>>Â Â Â Â Â Â Â Â Â Â Â Â Â </xsl:when>
>>Â Â Â Â Â Â Â Â Â Â Â Â Â <xsl:otherwise>
>>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <xsl:value-of
>>select="following-sibling::*[not(self::source)][1]/preceding-sibling::*[self::source][preceding-sibling::current()]"/>
>>Â Â Â Â Â Â Â Â Â Â Â Â Â </xsl:otherwise>
>>Â Â Â Â Â Â Â Â Â Â </xsl:choose>
>>
>>That is, test whether there are non-"foo" following siblings. If there
>>are none, take all following siblings. If there are, go forward to the
>>first non-"foo" sibling, and from there go backwards, taking all the
>>"foo" siblings up to the current node.
>>
>>But this does not work. Apparently, the expression
>>"preceding-sibling::current()" is not a valid construct. So what is the
>>correct way to do what I have in mind (or a simpler solution, if there
>>is one). Please note that this stylesheet needs to be executed by a web
>>browser, and so the solution has to remain within XPath 1.0.
>>
>>Thanks in advance for your help!
>>Wolfhart
--
Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/s/ |
Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Streaming hands-on XSLT/XPath 2 training class @US$125 (5 hours free) |
Essays (UBL, XML, etc.) http://www.linkedin.com/today/author/gkholman |
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/3329386
or by email: [email protected]
--~--