Xml file is use as input to transformatiio
<SNXDispositionUpdatedMessage
xmlns="urn:tracelink:mapper:sl:serial_number_exchange"
xmlns:cmn="urn:tracelink:mapper:sl:commontypes">
<ControlFileHeader>
<cmn:FileSenderNumber>0358716000006</cmn:FileSenderNumber>
</ControlFileHeader>
</SNXDispositionUpdatedMessage>
xlst file is used to transform rules
<xsl:stylesheet version="2.0"
xmlns="urn:tracelink:mapper:sl:serial_number_exchange"
xmlns:cmn="urn:tracelink:mapper:sl:commontypes"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<validation>
<xsl:apply-templates
select="SNXDispositionUpdatedMessage/ControlFileHeader"/>
<xsl:apply-templates
</validation>
</xsl:template>
<xsl:template match="SNXDispositionUpdatedMessage/ControlFileHeader">
<fieldvalidation>
<xsl:choose>
<xsl:when test="cmn:FileSenderNumber != ''">
<validtedfield>FileSenderNumber</validtedfield>
<value><xsl:value-of select="cmn:FileSenderNumber"/></value>
<status>Valid</status>
<reason></reason>
</xsl:when>
<xsl:otherwise>
<validtedfield>FileSenderNumber</validtedfield>
<value><xsl:value-of select="cmn:FileSenderNumber"/></value>
<status>Not Valid</status>
<reason>FileSenderNumber should not be empty.</reason>
</xsl:otherwise>
</xsl:choose>
</fieldvalidation>
</xsl:template>
</xsl:stylesheet>
当前输出
<?xml version="1.0" encoding="UTF-8"?>
<validation xmlns="urn:tracelink:mapper:sl:serial_number_exchange"
xmlns:cmn="urn:tracelink:mapper:sl:commontypes"/>
<validation xmlns="urn:tracelink:mapper:sl:serial_number_exchange"
xmlns:cmn="urn:tracelink:mapper:sl:commontypes"/>
当我使用没有cmn名称空间时,xslt转换工作正常。 cmn namespace的问题。如何解决这个问题?标记中使用的cmn名称空间,没有cmn名称空间标题,转换终止。
答案 0 :(得分:0)
xmlns:t="urn:tracelink:mapper:sl:serial_number_exchange"
在XSLT中(在本例中为t)并使用前缀viz访问元素。
t:SNXDispositionUpdatedMessage or t:ControlFileHeader
或最好的方法使用命名空间cmn add和xml标签作为示例
cmn:ControlFileHeader