我希望从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:对应于w14和w15名称空间的末尾可忽略。
使用可忽略的命名空间删除任何节点的正确方法是什么。这需要动态完成,因为它可以通过预处理验证发送的任何xml doc进行更改。
修改
包括我当前的设置,没有任何动态删除(只有硬编码的命名空间)......
<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>
答案 0 :(得分:1)
尝试
<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]"/>