从属性中删除xmlns:fm

从属性中删除xmlns:fm,xml,xslt,xml-namespaces,Xml,Xslt,Xml Namespaces,我知道这类问题已经被回答了很多次,但从昨天起我所能找到的所有解决方案都不适用于我 我有第一个XSL文件,它将“自定义”XML Framemaker文件转换为DITA文件。出于某些原因,我有第二个XSL文件,用于“清理”获取的DITA文件: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

我知道这类问题已经被回答了很多次,但从昨天起我所能找到的所有解决方案都不适用于我

我有第一个XSL文件,它将“自定义”XML Framemaker文件转换为DITA文件。出于某些原因,我有第二个XSL文件,用于“清理”获取的DITA文件:

<?xml version="1.0" encoding="utf-8"?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

  <xsl:strip-space elements="*"/>

  <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
  </xsl:template>

  <xsl:template match="*[not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/>

  <xsl:template match="//title/text()[normalize-space()]">
   <xsl:value-of select="normalize-space()"/>
  </xsl:template>

  <xsl:template match="//title/text()[not(normalize-space())]" />

  <xsl:template match="table//footnote"><fn><xsl:value-of select="."/></fn></xsl:template>

  <xsl:template match="//para"><p><xsl:value-of select="."/></p></xsl:template>

  </xsl:stylesheet>
不起作用,它的派生词(使用name())也不起作用。我还试图在
xsl:stylesheet
中声明
xmlns:fm
,并排除前缀fm,但也不起作用

最奇怪的是
删除了所有属性,但没有
xmlns:fm

编辑:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp "&#xa0;">]>

<chapter RSID-Document = "BasisRS://OBJ_DOKU/11//001/1//11:63"
RSKM-DocuType = "Manual" RSKM-ProductType = "x"
RSKM-ProductGroup = "x"
RSKM-ProductName = "x" RSIM-Status = "3"
RSKM-Language = "EN" chaptertype = "train" ActivateFilter = "Off">
<title
id = "P_12bcc27e" startposition = "topofpage">x</title>
<module id = "P_67912cfb" xmlns:fm = "fctfmns.xml"
RSID-Component = "BasisRS://OBJ_BAUST/906/EN/001/1//925:2"
RSIM-Checksum = "4ad808b1" RSIM-XRefID = "UID:906:3:9f1e5d1">
    <topic>
        <title id = "P_37e7a2f6" RSIM-XRefID = "UID:906:1:9f1e5c1">x</title>
        <table frame = "all" colsep = "1" rowsep = "1" id = "P_982c71a0"
RSIM-XRefID = "UID:906:2:9f1e5c1">
            <tgroup cols = "2" colsep = "1" rowsep = "1" outputclass = "General">
                <colspec colnum = "1" colname = "1" colwidth = "28*"/>
                <colspec colnum = "2" colname = "2" colwidth = "72*"/>
                <thead>
                    <row rowsep = "1">
                        <entry colname = "1">
                            <para>x</para>
                        </entry>
                        <entry colname = "2">
                            <para>x</para>
                        </entry>
                    </row>
                </thead>
                <tbody>
                    <row rowsep = "1">
                        <entry colname = "1">
                            <para>x</para>
                        </entry>
                        <entry colname = "2">
                            <para>x</para>
                        </entry>
                    </row>
                    <row rowsep = "1">
                        <entry colname = "1">
                            <para>x</para>
                        </entry>
                        <entry colname = "2">
                            <para>x</para>
                        </entry>
                    </row>
                    <row rowsep = "1">
                        <entry colname = "1">
                            <para>x</para>
                        </entry>
                        <entry colname = "2">
                            <para>x</para>
                        </entry>
                    </row>
                    <row rowsep = "1">
                        <entry colname = "1">
                            <para>x</para>
                        </entry>
                        <entry colname = "2">
                            <para>x</para>
                        </entry>
                    </row>
                    <row rowsep = "1">
                        <entry colname = "1">
                            <para>x</para>
                        </entry>
                        <entry colname = "2">
                            <para>x</para>
                        </entry>
                    </row>
                    <row rowsep = "1">
                        <entry colname = "1">
                            <para>x</para>
                        </entry>
                        <entry colname = "2">
                            <para>x</para>
                        </entry>
                    </row>
                    <row rowsep = "1">
                        <entry colname = "1">
                            <para>x</para>
                        </entry>
                        <entry colname = "2">
                            <para>x</para>
                        </entry>
                    </row>
                    <row rowsep = "0">
                        <entry colname = "1">
                            <para>x</para>
                        </entry>
                        <entry colname = "2">
                            <para>x</para>
                        </entry>
                    </row>
                </tbody>
            </tgroup>
        </table>
    </topic>
</module>
</chapter>

x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
(所需输出写在上面)


请注意,xmlns:fm名称空间位于输入的module元素中,但取决于我测试的解决方案,xmlns:fm名称空间会出现在表、主题、标题、,或者最常用于tgroup元素。

假设您确实使用XSLT 2.0处理器,并且名称空间声明是从您的输入中复制的,那么您可以更改模板

  <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
  </xsl:template>
而不是

  <xsl:template match="node()|@*">
  <xsl:copy copy-namespaces="no">
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
  </xsl:template>

您的方法的问题是,您正在按原样复制整个表,这也会复制此时范围内的所有名称空间

要避免此情况,请更换此:

<xsl:template match="table">
    <xsl:copy-of select="."/>
</xsl:template>

与:



注意:这是指您发布的样式表-与您的问题中的样式表非常不同。

您发布的样式表没有或创建
表xmlns:fm=“fctfmns.xml”
,因此,在输出中具有类似名称空间声明的任何元素都可能是从输入中复制的(您根本没有显示)。“最奇怪的是,
删除了所有属性,但没有删除xmlns:fm。”不,这一点也不奇怪。名称空间声明不是一个属性。你能链接到一些不起作用的答案吗?那么我们知道应该避免什么提示了?谢谢!以下是输入和“主要”XSL表(在清理之前)中的相关部分:@Mousey我尝试添加
,将
修改为
,在XSL:stylesheet中添加xmlns:fm并排除前缀fm,尝试了functx函数“remove attribute”我花了很多时间,因为我在两个XSL表中都尝试了所有这些解决方案。谢谢!我检查了msxml.exe是否支持XSL 2.0,但实际上它不支持。。。XSL 1.0中是否存在等效性?请尝试使用
..
而不是
..
。我是XSL的初学者,我应该用
替换“…”吗?我应该用table或其他什么来替换“name”吗?我已经编辑了答案并提供了两个模板的代码,您应该在发布时使用它们(
name()
是一个函数调用)。非常感谢Martin,它很有效!现在我只能在Michael的解决方案和你的解决方案之间做出选择!非常感谢迈克尔,它解决了我的问题!下一次我会试着更好地准备我的问题!
  <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
  </xsl:template>
  <xsl:template match="node()|@*">
  <xsl:copy copy-namespaces="no">
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
  </xsl:template>
<xsl:template match="*">
  <xsl:element name="{name()}" namespace="{namespace-uri()}">
    <xsl:apply-templates select="@* | node()"/>
  </xsl:element>
</xsl:template>

<xsl:template match="@*">
  <xsl:attribute name="{name()}" namespace="{namespace-uri()}">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>
  <xsl:template match="node()|@*">
  <xsl:copy copy-namespaces="no">
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
  </xsl:template>
<xsl:template match="table">
    <xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="table"> 
    <xsl:apply-templates select="." mode="remove-namespaces"/>
</xsl:template> 

<xsl:template match="*" mode="remove-namespaces">
    <xsl:element name="{local-name()}">
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates mode="remove-namespaces"/>
    </xsl:element>
</xsl:template>