2012-02-19 80 views
14

下面是我的XSL如何从输出xml中删除命名空间?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:ms="http://www.test.com/schemas/test" 
xmlns:ns="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="ms ns"> 
<xsl:output method="xml" indent="yes"/> 

<xsl:template match="/"> 
<XMLResponse>   
    <xsl:apply-templates select="ms:ProductRS/ms:Product"/> 
</XMLResponse> 
</xsl:template> 
<-- some templates here --> 
</xsl:stylesheet> 

在输出我越来越像下面

<?xml version="1.0" encoding="UTF-16"?> 
<XMLResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<Product>-----</Product> 
</XMLResponse> 

我需要从XML输出中删除xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

+0

什么环境,你在工作,而且是在XMLResponse线XSI命名空间的唯一参考? – 2012-02-19 19:28:32

+0

为什么你需要删除该命名空间?你为什么想要? – 2012-02-19 19:47:36

回答

41

要排除的命名空间,那么你应该代表这样: -

exclude-result-prefixes="ms ns xsi

基本上你的样式看起来是这样的: -

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:ms="http://www.test.com/schemas/test" 
xmlns:ns="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="ms ns xsi"> 
+1

或者,如果xsi前缀没有在样式表中的任何位置使用,并且在输出中不需要,则只需删除该声明即可。 – 2012-02-19 22:45:17

+0

非常有用,谢谢! – ClaudioM 2015-12-14 16:33:00