Re: [xsl] Add id to next element

Subject: Re: [xsl] Add id to next element
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 20 May 2022 01:52:22 -0000
On Fri, May 20, 2022 at 01:34:41AM -0000, Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx scripsit:
> Hi Graydon,

Hello!

> > What's wrong with
> >
> > <xsl:template match="section">
> >     <xsl:copy>
> >     	<xsl:apply-templates select="@*" mode="#current" />
> >	<xsl:attribute name="id"
> >	  select="(preceding-sibling::*[1][self::target]/@refid,generate-id(.)) => head()" />
> >	<xsl:apply-templates mode="#current" />
> >     </xsl:copy>
> > </xsl:template>
> 
> I normally use (expr1, expr2)[1] as an if-then-else for expressions evaluating to 0 or 1 node,

I think it was Liam Quinn who pointed out that head() is smart about not
picking up null strings while (expr1, expr2)[1] is not.  I have found
head() just plain More Useful as a pattern for "I want the first
defined thing in this sequence".

> but that arrow syntax is pretty neat. I should start using it.

It's likely a deficiency in my noggin, but I find remembering the
sequence parens is a lot easier when it reads as "make the sequence on
the left the first parameter of the function on the right". (Something
that can be vital with two maps and map:merge()!)

The arrow operator is great for things like chained replaces, too; MUCH
easier to read and edit replace() => replace() => replace() than
replace(replace(replace())).

-- 
Graydon Saunders  | graydonish@xxxxxxxxx
^fs oferiode, pisses swa mfg.
-- Deor  ("That passed, so may this.")

Current Thread