Good catch on the order David, thank you.
From: David Carlisle d.p.carlisle@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, October 16, 2026 6:12 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: Process an element once
you are just missing a template to drop the x that you have copied under p add
<xsl:template match="x[preceding-sibling::*[1][self::p]]"/>
and you get
<?xml version="1.0" encoding="UTF-8"?>
<root>
<x>not a child of p</x>
<p>1</p>
<p>2</p>
<p>
<x>child of p</x>3</p>
<p>4</p>
</root>
although I would ave expected to prcess the child of p before pulling in the x
so the text stayed in original order
so
<?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:apply-templates/>
<xsl:apply-templates select="following-sibling::*[1][self::x]"
mode="child-x"/>
</xsl:copy>
</xsl:template>
<xsl:template match="x" mode="child-x">
<xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>
<xsl:template match="x[not(preceding-sibling::*[1][self::p])]">
<xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>
<xsl:template match="x[preceding-sibling::*[1][self::p]]"/>
</xsl:stylesheet>
producing
<?xml version="1.0" encoding="UTF-8"?>
<root>
<x>not a child of p</x>
<p>1</p>
<p>2</p>
<p>3<x>child of p</x>
</p>
<p>4</p>
</root>
David
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/612310> (by
email <> )
|