Why do I get the xmlns=""? I've tried putting the namespace in many other places and messed with the prefix but can't seem to remove the empty xmlns="" attributes.
XML:
<?xml version="1.0" encoding="utf-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.09">
<CstmrCdtTrfInitn>
<GrpHdr>
<MsgId>15957</MsgId>
<CreDtTm>2025-05-14T03:03:11.917-07:00</CreDtTm>
<NbOfTxs>3</NbOfTxs>
<CtrlSum>30</CtrlSum>
<InitgPty>
<Nm>GtmtpTest</Nm>
</InitgPty>
</GrpHdr>
<PmtInf>
<PmtInfId>159571</PmtInfId>
<PmtMtd>TRF</PmtMtd>
<BtchBookg>false</BtchBookg>
<NbOfTxs>3</NbOfTxs>
<CtrlSum>30</CtrlSum>
<PmtTpInf>
<InstrPrty>NORM</InstrPrty>
<LclInstrm>
<Cd>STANDARD</Cd>
</LclInstrm>
</PmtTpInf>
<ReqdExctnDt>
<Dt>2025-05-14</Dt>
</ReqdExctnDt>
...
XSLT:
<?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:this="urn:iso:std:iso:20022:tech:xsd:pain.001.001.09"
exclude-result-prefixes="xs"
version="3.0">
<xsl:namespace-alias stylesheet-prefix="this" result-prefix=""/>
<xsl:mode streamable="yes" on-no-match="shallow-copy"/>
<xsl:template match="this:PmtTpInf" >
<xsl:apply-templates select="copy-of()" mode="in-memory"/>
</xsl:template>
<xsl:template match="this:PmtTpInf" mode="in-memory">
<this:First_Name><xsl:value-of select="'BUSINESS'"/></this:First_Name>
<this:Last_Name><xsl:value-of select="'MAN'"/></this:Last_Name>
</xsl:template>
</xsl:stylesheet>
Output:
<?xml version="1.0" encoding="UTF-8"?><Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.09">
<CstmrCdtTrfInitn>
<GrpHdr>
<MsgId>15957</MsgId>
<CreDtTm>2025-05-14T03:03:11.917-07:00</CreDtTm>
<NbOfTxs>3</NbOfTxs>
<CtrlSum>30</CtrlSum>
<InitgPty>
<Nm>GtmtpTest</Nm>
</InitgPty>
</GrpHdr>
<PmtInf>
<PmtInfId>159571</PmtInfId>
<PmtMtd>TRF</PmtMtd>
<BtchBookg>false</BtchBookg>
<NbOfTxs>3</NbOfTxs>
<CtrlSum>30</CtrlSum>
<First_Name xmlns="">BUSINESS</First_Name><Last_Name xmlns="">MAN</Last_Name>
<ReqdExctnDt>
<Dt>2025-05-14</Dt>
</ReqdExctnDt>
xsl:namespace-alias, as the posted answer suggests, I think you want e.g.xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.09"and<xsl:namespace-alias stylesheet-prefix="this" result-prefix="#default"/>but I am not sure Saxon gets it right then. Not sure what is going on. There are some test cases forresult-prefix="#default"that do work.