[Top] [All Lists]

Re: [xsl] Add id to next element

2022-05-19 17:03:18
Nothing wrong with that formulation—I guess I have enough XSLT 2 brain damage 
that I forget about being able to select the head of a possibly multi-item 
sequence as a shortcut for the if/then/else I wrote 😊

I spend a lot of time (or have spent) correcting older XSLT code to use exactly 
that formulation so I should really start there …



Eliot Kimber
Sr Staff Content Engineer
O: 512 554 9368
M: 512 554 9368
LinkedIn<https://www.linkedin.com/company/servicenow> | 
Twitter<https://twitter.com/servicenow> | 
YouTube<https://www.youtube.com/user/servicenowinc> | 

From: Graydon graydon(_at_)marost(_dot_)ca 
Date: Thursday, May 19, 2022 at 1:47 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
Subject: Re: [xsl] Add id to next element
[External Email]

On Thu, May 19, 2022 at 05:53:58PM -0000, Eliot Kimber 
eliot(_dot_)kimber(_at_)servicenow(_dot_)com scripsit:
The typical way to do it is to have the processing of the section element get
the value from the preceding target element:

  <xsl:template match="section">
    <xsl:variable name="id" as="xs:string?"
        <xsl:attribute name="id"
          select="if ($id) then $id else generate-id(.)"
        <xsl:apply-templates mode="#current"/>

What's wrong with

<xsl:template match="section">
        <xsl:apply-templates select="@*" mode="#current" />
        <xsl:attribute name="id"
=> head()" />
        <xsl:apply-templates mode="#current" />

I am assuming XSLT 3, here, but that should be a fairly safe assumption
these days.

Graydon Saunders  | graydonish(_at_)gmail(_dot_)com
Þæs oferéode, ðisses swá mæg.
-- Deor  ("That passed, so may this.")

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
<Prev in Thread] Current Thread [Next in Thread>