2012-02-19 81 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