2013-06-12 90 views
0

我試圖在edifabric x12 xml文件上執行簡單的xsl轉換。 我如何選擇<D_744_1>元素?選擇具有名稱空間的元素的值

示例XML:

<INTERCHANGE xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="www.edifabric.com/x12"> 
    <S_ISA> 
     <D_744_1>00</D_744_1> 
    </S_ISA> 
</INTERCHANGE> 

樣品XSL:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"> 
     <testfield><xsl:value-of select="INTERCHANGE/S_ISA/D_744_1" /></testfield> 
    </xsl:template> 
</xsl:stylesheet> 

結果:

<?xml version="1.0" encoding="utf-8"?> 
<testfield/> 

所需的結果:

<?xml version="1.0" encoding="utf-8"?> 
    <testfield>00</testfield> 

更新的答案感謝@ChriPf

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:edi="www.edifabric.com/x12" exclude-result-prefixes="edi"> 

    <xsl:template match="edi:INTERCHANGE"> 
     <testfield><xsl:value-of select="edi:S_ISA/edi:D_744_1" /></testfield> 
    </xsl:template> 

</xsl:stylesheet> 
+0

請問您能否插入想要的結果來顯示問題所在? – ChriPf

回答

1

您的解決方案可能是這樣的:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:edi="www.edifabric.com/x12"> 
    <xsl:template match="edi:D_744_1"> 
    <xsl:element name="testfield"> 
     <xsl:copy-of select="." /> 
    </xsl:element> 
</xsl:template> 
</xsl:stylesheet> 

如果你在你的XML默認命名空間,你必須在XSL來定義它好。查找更多信息here

+0

結果看起來很奇怪。 <?xml version =「1.0」encoding =「utf-8」?> 00它的值沒有xml元素 – Belial09

+0

我已經更新了答案,現在就工作。 – ChriPf

+0

當我在http://www.online-toolz.com/tools/xslt-transformation.php上或http://www.freeformatter.com/xsl-transformer.html或http:// markbucayan .appspot.com/xslt/index.html我得到一個錯誤或結果沒有xml元素,只是值00.氧氣給了我相同的結果(沒有名爲testfield的xml元素): -/ – Belial09

相關問題