[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: with XPath 1.0, select all following sibling eleme

Subject: Re: with XPath 1.0, select all following sibling elements of name "foo" up to the first non-"foo" element
From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 18 Feb 2021 22:26:16 -0000
Re:  with XPath 1.0
Indeed, I was going to add that the "real" way to do this under 1.0 was
XSLT sibling recursion, but I forgot.

Thanks David!


On Thu, Feb 18, 2021 at 4:35 PM David Carlisle d.p.carlisle@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

>
> > I am facing an XPath problem
>
> The answers so far have answered the question asked, but I wonder if that
> is the wrong question.
>
> To select the consecutive sequence of foo elements in xpath 1 requires
> some kind of double pass over the list and quadratic behaviour in the
> number of elements in the list.
>
> However if (as appears the case) the question is in an XSLT context rather
> than pure Xpath, you can usually avoid selecting the elements in a single
> expression.
> this does a single pass over the list stopping at the first non-foo
> element so is linear complexity
>
> xpath is just used to select one element at a time, the logic of handling
> just foo elements is pushed to a specific XSLT mode that only handles foo
> and stops at anything else,
>
> Given
>
> <x>
>
>  <b>
>   <foo>1</foo>
>   <foo>2</foo>
>   <bar>x</bar>
>   <foo>3</foo>
>  </b>
>
>  <b>
>   <foo>4</foo>
>   <foo>5</foo>
>   <foo>6</foo>
>  </b>
>
>  <b>
>   <bar>y</bar>
>   <foo>7</foo>
>   <foo>8</foo>
>  </b>
>
> </x>
>
>
> this stylesheet
>
> <xsl:stylesheet version="1.0" xmlns:xsl="
> http://www.w3.org/1999/XSL/Transform">
>
>  <xsl:template match="b">
>    <zzz>
>    <xsl:apply-templates mode="onlyfoo" select="*[1]"/>
>    </zzz>
>  </xsl:template>
>
>  <xsl:template mode="onlyfoo" match="*"/>
>
>  <xsl:template mode="onlyfoo" match="foo">
>   <xsl:copy-of select="."/>
>   <xsl:apply-templates mode="onlyfoo" select="following-sibling::*[1]"/>
>  </xsl:template>
>
> </xsl:stylesheet>
>
>
> produces
>
>
>  <zzz><foo>1</foo><foo>2</foo></zzz>
>
>  <zzz><foo>4</foo><foo>5</foo><foo>6</foo></zzz>
>
>  <zzz/>
>
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/174322> (by
> email <>)
>


-- 
...Wendell Piez... ...wendell -at- nist -dot- gov...
...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.