On 16/10/2026 23:11, rick@xxxxxxxxxxxxxx wrote:
>
> I have this XML:
>
> <root>
>
> B B B <x>not a child of p</x>
>
> B B B <p>1</p>
>
> B B B <p>2</p>
>
> B B B <p>3</p>
>
> B B B <x>child of p</x>
>
> B B B <p>4</p>
>
> </root>
>
> If an <x> element immediately follows a <p>, I want to make it a child
> of the <p>:
>
> <root>
> B B <x>not a child of p</x>
> B B <p>1</p>
> B B <p>2</p>
> B B <p>
> B B B B B <x>child of p</x>3</p>
> B B B <p>4</p>
> </root>
>
Or as another option
B <xsl:mode on-no-match="shallow-copy"/>
B <xsl:template match="p[following-sibling::*[1][self::x]]">
B B <xsl:copy>
B B B <xsl:copy-of select="following-sibling::*[1], node()"/>
B B </xsl:copy>
B </xsl:template>
B <xsl:template match="x[preceding-sibling::*[1][self::p]]"/>
|