2017-08-06 100 views
0

有輸入XML的格式如下:XSLT的命名空間元素

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Header/> 
    <s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <ResponseData xmlns="http://testify.com/maxi"> 
     <VALID>true</VALID> 
     <ERROR_DESC xsi:nil="true"> something gone wrong </ERROR_DESC> 
    </ResponseData> 
    </s:Body> 
</s:Envelope> 

它越來越難以將其轉換成如下由於其複雜的格式,由於命名空間。

​​

我試過了幾個沒有成功的選項。在下面導致沒有數據。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
<xsl:output method="xml" encoding="utf-8" indent="no"/> 
<xsl:template match="/"> 
    <xsl:value-of select="s:Envelope//s:Body/s:ResponseData"/> 
</xsl:template> 


    <xsl:template match="s:ResponseData"> 
    <xsl:element name="width"> 
     <xsl:value-of select="s:VALID"/> 
    </xsl:element> 
    </xsl:template> 


</xsl:stylesheet> 
+0

如果你想''作爲包裝,那麼你爲什麼要求''?! –

回答

3

得到結果在你的問題中指定,您需要:

(一)解決ResponseData元素及其子當使用正確的命名空間; (b)通過應用模板實際處理ResponseData的子女。

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:m="http://testify.com/maxi" 
exclude-result-prefixes="m"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:template match="m:ResponseData"> 
    <STATUS> 
     <xsl:apply-templates/> 
    </STATUS> 
</xsl:template> 

<xsl:template match="m:*"> 
    <xsl:element name="{local-name()}"> 
     <xsl:apply-templates/> 
    </xsl:element> 
</xsl:template> 

</xsl:stylesheet> 

注意,沒有什麼是爲了不復制命名空間被複制。