[英]select value of an element which has a namespace assigned
i'm trying to do a simple xsl transformation on an edifabric x12 xml file. 我正在尝试对edifabric x12 xml文件进行简单的xsl转换。 How can i select the <D_744_1>
Element? 如何选择<D_744_1>
元素?
Sample XML: 样本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>
Sample XSL: 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>
Result: 结果:
<?xml version="1.0" encoding="utf-8"?>
<testfield/>
Desired Result: 预期结果:
<?xml version="1.0" encoding="utf-8"?>
<testfield>00</testfield>
updated answer thanks @ChriPf : 更新的答案谢谢@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>
Your solution could look like this: 您的解决方案可能如下所示:
<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>
If you have a default namespace in your xml, you have to define it in the xsl as well. 如果您的xml中有默认名称空间,则也必须在xsl中定义它。 Find some more information eg here . 在此处找到更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.