[Top] [All Lists]

Re: [xsl] Add id to next element

2022-05-19 22:08:21
Thank you for the solution! I see that I was looking the wrong way.
Instead of looking forward from <target> to <section>, I should have
looked backward at <target> from <section>.  I have modified your code
to suit the actual XML I am transforming, and it works perfectly.


On Thu, May 19, 2022 at 11:21 PM Michael Kay mike(_at_)saxonica(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

You don't do it while processing the target element, you do it while 
processing the section element

<xsl:template match="section">
    <xsl:attribute name="id" select="preceding-sibling::target/@refid"/>

Michael Kay

On 19 May 2022, at 18:18, Raghavendra Nyshadham 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

I am trying to write an XSLT stylesheet to transform an XML document
(that was generated by Python Docutils) to HTML5. Here is a fragment
from the source document:

<target refid="foo"/>

The <target> element specifies an identifier for the next element,
i.e., <section>. So I want something like

<section id="foo">

in the HTML output. I am unable to figure out an XSLT way to attach an
attribute to the next element while processing <target>. Would
appreciate any help.

Thanks and regards,

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>