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

Re: Add id to next element

Subject: Re: Add id to next element
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 20 May 2022 01:52:22 -0000
Re:  Add id to next element
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

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.