动态删除 mc:Ignorable 个命名空间

Removing mc:Ignorable namesapces dynamically

我想从 ooxml 规范文档中删除任何 mc:ignorable 命名空间。

例如(取自 docx numbering.xml...)

<w:numbering xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 wp14"><w:numbering xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 wp14">

注意末尾的 mc:ignorable 对应于 w14 和 w15 命名空间。

使用可忽略命名空间删除任何节点的正确方法是什么。这需要动态完成,因为它可以随着通过预处理发送的任何 xml 文档进行更改以进行验证。

编辑

包括我当前的设置,没有任何动态删除(仅硬编码命名空间)...

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output indent="no" method="xml" omit-xml-declaration="no" />
    <xsl:strip-space elements="*" />

<!-- Identity transform. Also known as "Copy everything". -->
<xsl:template match="@* | node()" name="identity">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
</xsl:template>

我的硬编码命名空间将被删除

    <xsl:template match="node()[namespace-uri()='http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing']|@*[namespace-uri()='http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing']" />
<xsl:template match="node()[namespace-uri()='http://schemas.microsoft.com/office/word/2010/wordml']|@*[namespace-uri()='http://schemas.microsoft.com/office/word/2010/wordml']" />
<xsl:template match="node()[namespace-uri()='http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac']|@*[namespace-uri()='http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac']" />
</xsl:stylesheet>

尝试

<xsl:variable xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" name="namespaces-to-remove" select="for $prefix in /*/tokenize(@mc:Ignorable, ' ') return namespace-uri-for-prefix($prefix, /*)"/>

<xsl:template  match="node()[namespace-uri() = $namespaces-to-remove] | @*[namespace-uri() = $namespaces-to-remove]"/>