2016-11-08 27 views
0

源XML包含自定義命名空間:如何執行XSL轉換如果自定義命名空間用來

<?xml version='1.0' encoding='UTF-8'?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Body> 
    <ns:getBuyInvoiceResponse xmlns:ns="http://iws.itella.ee"> 
     <ns:return> 
     <E_Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
... 

XSL contaisn還有那些命名空間:

<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:ns="http://iws.itella.ee" 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 

,他們在選擇使用

<xsl:template match="/soapenv:Envelope/soapenv:Body/ns:getBuyInvoiceResponse/E_Invoice/Invoice/InvoiceItem/InvoiceItemGroup/*"> 

使用http://www.utilities-online.info/xsltransformation的XSLT轉換會創建空文檔。如何解決這個問題,以便文檔內容也被創建?

回答

1

首先,E_Invoicens:return的孩子,而不是ns:getBuyInvoiceResponse - 因此您的第二個模板沒有任何匹配。

還要注意的是匹配模式是從選擇表達不同:你不需要拼出完整路徑。這:

<xsl:template match="InvoiceItemGroup/*"> 

本來工作得很好。

最後,請注意,如果必須計算元素的名稱,則只需使用xsl:element。否則,使用文字結果元素會更短,更好。