How to exclude namespace (re)declarations in Schematron Quick fixes
Posted: Wed Jul 09, 2025 1:46 pm
I'm working with XML documents that have the relevant namespaces declared solely on the root element, and (for mostly stylistic reasons) I'd like to retain that.
When a schematron quick fix containing an xsl template operates on a fragment within the document, the XSLT processor will insert a (redundant) xmlns="..." declaration onto descendants of the element being replaced, thus ignoring the declarations already present in the broader, original document context.
Are there any methods that can be used to avoid this behaviour?
Here's a simplified example to reproduce the behaviour:
Input XML:
Schematron:
Output after fix:
Note the xmlns:xlink="http://www.w3.org/1999/xlink" declaration on the new title element.
I'm working with oXygen XML Editor version 26.
When a schematron quick fix containing an xsl template operates on a fragment within the document, the XSLT processor will insert a (redundant) xmlns="..." declaration onto descendants of the element being replaced, thus ignoring the declarations already present in the broader, original document context.
Are there any methods that can be used to avoid this behaviour?
Here's a simplified example to reproduce the behaviour:
Input XML:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<article xmlns:xlink="http://www.w3.org/1999/xlink">
<fig>
<caption>
<p>This is the title <ext-link ext-link-type="uri" xlink:href="https://schematron.com/">link</ext-link>.</p>
<p>This is the caption.</p>
</caption>
</fig>
</article>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://purl.oclc.org/dsdl/schematron"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sqf="http://www.schematron-quickfix.com/validator/process"
queryBinding="xslt3">
<xsl:template match="." mode="customCopy">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="*|@*|text()|comment()|processing-instruction()" mode="customCopy"/>
</xsl:copy>
</xsl:template>
<sqf:fixes>
<sqf:fix id="replace-p-to-title">
<sqf:description>
<sqf:title>Change the p to title</sqf:title>
</sqf:description>
<sqf:replace match="./p[1]">
<xsl:element name="title">
<xsl:apply-templates select="node()|comment()|processing-instruction()" mode="customCopy"/>
</xsl:element>
</sqf:replace>
</sqf:fix>
</sqf:fixes>
<pattern id="fig">
<rule context="fig/caption" id="fig-caption-checks">
<report test="not(title) and (count(p) gt 1)"
role="warning"
sqf:fix="replace-p-to-title"
id="fig-caption-1">Caption for fig doesn't have a title, but there are mutliple paragraphs. Is the first paragraph actually the title?</report>
</rule>
</pattern>
</schema>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<article xmlns:xlink="http://www.w3.org/1999/xlink">
<fig>
<caption>
<title>This is the title <ext-link ext-link-type="uri" xlink:href="https://schematron.com/" xmlns:xlink="http://www.w3.org/1999/xlink">link</ext-link>.</title>
<p>This is the caption.</p>
</caption>
</fig>
</article>
I'm working with oXygen XML Editor version 26.