When running the below XSLT
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xquery="http://www.w3.org/2005/xpath-functions"
xmlns:upd="http://www.w3.org/2007/xquery-update-10">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="document('f1.xml')">
<xsl:variable name="doc" select="."/>
<xsl:variable name="newFileName" select="concat(substring-before(document-uri($doc), '.xml'), '_chg.xml')" />
<xsl:result-document href="{$newFileName}">
<xsl:apply-templates select="$doc/*"/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
<!-- Template to match the root element -->
<xsl:template match="/">
<xsl:apply-templates select="*"/>
</xsl:template>
<!-- Identity template to copy all nodes and attributes -->
<xsl:template match="@*|node()">
<xsl:copy>
<!-- Copy attributes first -->
<xsl:apply-templates select="@*"/>
<!-- Then copy child nodes -->
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The following error is produced.
XTDE0410: Cannot add attribute node to an element node that already has non attribute or namespace children
Why, the attributes are clearly copied before the nodes in the "copy" node.
Tried removing the node in the XML with the attributes listed in the error message, no change, just errors on the next node. Tried removing the iterations through the list of files, no change. Tried combining the "@*" and "node()" on the apply-templates
Sample XML
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="file:///F:/temp%20(F)/2025-06-24a_debug/DataPower_Control_File_cleanup_actions_V3.xslt"?>
<registeredServices>
<domain name="entsvcs" description="Enterprise Services">
<service name="commonlogging" version="1.0" type="SOAP" endpoint="http://localhost:3016" sldpolicy="default_sld_policy">
<registeredConsumers>
<!--
<consumer><consumerId></consumerId><consumerName></consumerName><clientName></clientName><slaPolicy>bcbst_default_sla_policy</slaPolicy><logLevel>0</logLevel>
-->
<!-- 0 = ALL, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=FATAL, 6=OFF -->
<!--
</consumer>
-->
<consumer>
<consumerId>bcbstesvcs</consumerId>
<consumerName>BCBST</consumerName>
<clientName>Enterprise Services</clientName>
<slaPolicy>bcbst_default_sla_policy</slaPolicy>
<logLevel>1</logLevel>
</consumer>
</registeredConsumers>
</service>
</domain>
</registeredServices>
<xsl:template match="/">twice? Which template do you expect to be used? Also o post a minimal input that allows us to reproduce the error with the code shown.