這裏是我的XML源刪除屬性各個節點在XSLT
<?xml version="1.0" encoding="UTF-8"?>
<tns:Grand_Parent_XML xmlns:tns="http://www.domain.com/">
<GrandParent>
<Parent>
<Child xmlns:tns="http://www.domain.com/">
<Age>3</Age>
<Gender>Male</Gender>
<Name>Todd</Name>
</Child>
<Other>1234</Other>
</Parent>
</GrandParent>
</tns:Grand_Parent_XML>
這裏就是我使用XSLT的身體......
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Grand_Parent_XML">
<xsl:element name="tns:{name()}" namespace="http://www.domain.com/">
<xsl:copy-of select="namespace::*"/>
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:if test="normalize-space(string(.)) != ''">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="Parent">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<Child>
<xsl:apply-templates select="Child/*"/>
</Child>
</xsl:copy>
</xsl:template>
<xsl:template match="Child"/>
我想刪除的xmlns:TNS =「」,並將其保留在Grand_Parent_XML中。我嘗試了其他建議,例如在XSLT底部創建以下代碼,但它不起作用。任何幫助將不勝感激。
<xsl:template match="Child">
<xsl:apply-templates />
</xsl:template>
'xmlns:tns =「」'無效。前綴名稱空間綁定可能不爲空。 – 2014-08-27 12:22:39
您的輸入XML格式不正確。如果您不更改名稱空間定義,則樣式表將不接受它作爲輸入。或者將XML版本設置爲「1.1」。 – 2014-08-27 12:23:50
對不起,我省略了原來的內容。我現在就更新它。 – edpalomo 2014-08-27 12:26:10