2013-06-12 87 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

相关问题