Subject: Re: [xsl] Process the following group From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 8 Jul 2022 16:16:05 -0000 |
Hi again, With the bug repaired -- <xsl:key name="myDivs" match="div2" use="(preceding-sibling::div1[1], following-sibling::div1)[1]/generate-id()"/> Lesson? XPath gives tremendous power enabling workarounds for even pesky exception conditions. Cheers, Wendell On Fri, Jul 8, 2022 at 10:09 AM Wendell Piez wapiez@xxxxxxxxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > Just writing again to note there's a bug in the code I just posted! :-> > > > On Fri, Jul 8, 2022 at 10:03 AM Wendell Piez wapiez@xxxxxxxxxxxxxxx < > xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > >> Rick, >> >> That being said, this can also be done in one pass, and indeed without >> xsl:for-each-group at all .... >> >> <xsl:key name="myDivs" match="div2" use="(preceding-sibling::div1, >> following-sibling::div1)[1]/generate-id()"/> >> >> <xsl:template match="div1"> >> <xsl:copy> >> <xsl:apply-templates select="key('myDivs',generate-id())" >> mode="include"/> >> </xsl:copy> >> </xsl:template> >> >> etc. >> >> This works on the principle that groups can be created by relating >> elements together using keys (old 1.0 approach). >> >> Not disagreeing with Eliot's advice here however -- splitting into >> multiple passes will often yield a more maintainable as well as clearer >> solution to a problem. A solution like this is both more obscure, and more >> apt to break when something subtle turns up. >> >> Cheers, Wendell >> >> >> >> On Fri, Jul 8, 2022 at 9:30 AM rick@xxxxxxxxxxxxxx < >> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: >> >>> Hi Eliot, thank you for walking me through the logic. It makes sense so >>> I will try to code it that way. But I think the advice from you and others >>> to do a multiple pass may be a more robust approach. Thanks to all that >>> responded. -Rick >>> >>> >>> >>> *From:* Eliot Kimber eliot.kimber@xxxxxxxxxxxxxx < >>> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> >>> *Sent:* Thursday, July 7, 2022 6:11 PM >>> *To:* xsl-list@xxxxxxxxxxxxxxxxxxxxxx >>> *Subject:* Re: [xsl] Process the following group >>> >>> >>> >>> So the first two div2 elements should be grouped with the first div1? >>> >>> >>> >>> If you do group-starting-with div1 then the first two div2s will be in >>> the first group and that group will not start with a div1, so you can have >>> logic to ignore that first group and then in a group that starts with >>> <div1>, you can pull any <div2> elements that do not have a <div1> >>> preceding sibling, which will get the <div2>s that would have formed the >>> first group. No subsequent group will have <div2>s that do not have a >>> <div1> preceding sibling. >>> >>> >>> >>> But this is also a case where it might be easier to pre-process your >>> content before grouping, for example, to move things so that therebs always >>> a <div1> before any <div2>s or what ever it might be. >>> >>> I generally find these kinds of challenges are most effectively solved >>> by breaking them into several steps, each one of which is relatively easy >>> to implement. >>> >>> >>> >>> Cheers, >>> >>> >>> >>> E. >>> 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... >> 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... > 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Process the following gro, Wendell Piez wapiez@ | Thread | Re: [xsl] XPath expression to conve, Roger L Costello cos |
Re: [xsl] Process the following gro, Wendell Piez wapiez@ | Date | Re: [xsl] XPath expression to conve, Dimitre Novatchev dn |
Month |