[Home] [By Thread] [By Date] [Recent Entries]

Subject: Re: Process an element once
From: "rick@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 16 Oct 2026 22:04:56 -0000
Thank you Martin and Syd. I probably made my example too simple. I have to use
apply-templates because I am making some significant changes to the structure.
So I am trying to see how to apply templates to the <x> element when it is
immediately after the <p> but not have the <x> element processed again after
the <p>. This seems to give me what I need:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:math="http://www.w3.org/2005/xpath-functions/math"
    exclude-result-prefixes="xs math"
    version="3.0" expand-text="yes">

    <xsl:output indent="yes"/>

    <xsl:template match="/root">
        <xsl:copy><xsl:apply-templates/></xsl:copy>
    </xsl:template>

    <xsl:template match="p">
        <xsl:copy>
            <xsl:choose>
                <xsl:when test="following-sibling::*[1][self::x]">
                    <xsl:apply-templates
select="following-sibling::*[1][self::x]" mode="child-of-p"/>
                </xsl:when>
            </xsl:choose>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="x" mode="child-of-p #unnamed">
        <x><xsl:apply-templates/></x>
    </xsl:template>

    <xsl:template match="x[preceding-sibling::*[1][self::p]]"/>

</xsl:stylesheet>





From: Martin Honnen martin.honnen@xxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, October 16, 2026 5:29 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Process an element once



Or as another option

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:template match="p[following-sibling::*[1][self::x]]">
    <xsl:copy>
      <xsl:copy-of select="following-sibling::*[1], node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="x[preceding-sibling::*[1][self::p]]"/>

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>

EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/612310>  (by
email <> )

Current Thread
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member