我的源XML是:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:DriverResponse xmlns:ns2="com/rsa/eosago/schema-1.1" xmlns:ns3="com/rsa/dkbm/schema-1.5">
<IDCheckDriver>84714718</IDCheckDriver>
<ErrorList>
<ErrorInfo>
<Code>2</Code>
<Message>Принят в обработку</Message>
</ErrorInfo>
</ErrorList>
</ns2:DriverResponse>
通缉输出:
<?xml version="1.0" encoding="UTF-8"?>
<rsa:DriverStatusRequest xmlns:rsa="com/rsa/eosago/schema-1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<InsurerID>18800000</InsurerID>
<IDCheckDriver>84714718</IDCheckDriver>
</rsa:DriverStatusRequest>
我希望从Apache Camel调用使用此XSL的输出:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext">
<xsl:param name="RSA-InsurerID"/>
<xsl:param name="EOSAGO-schema-version"/>
<xsl:param name="schema" select="concat('com/rsa/eosago/schema-', $EOSAGO-schema-version)"/>
<xsl:variable name="schemaUrlDummy">
<xsl:element name="ns2:dummy" namespace="{$schema}"/>
</xsl:variable>
<xsl:variable name="NS" select="ext:node-set($schemaUrlDummy)/*/namespace::ns2"/>
<xsl:template match="/">
<xsl:element name="rsa:DriverStatusRequest" namespace="com/rsa/eosago/schema-{$EOSAGO-schema-version}">
<InsurerID>
<xsl:value-of select="$RSA-InsurerID"/>
</InsurerID>
<xsl:element name="IDCheckDriver">
<xsl:copy-of select="namespace::*[not(name()='ns2')]"/>
<xsl:copy-of select="$NS"/>
<xsl:value-of select="ns2:DriverResponse/IDCheckDriver"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
骆驼设置:
<setHeader headerName="RSA-InsurerID">
<constant>18800000</constant>
</setHeader>
<setHeader headerName="EOSAGO-schema-version">
<constant>1.2</constant>
</setHeader>
<to uri="xslt:com/rsa/eosago/xsl/DriverResponse2DriverStatusRequest.xsl"/>
问题是我得到了这个错误堆栈跟踪
无法解析端点:xslt://com/rsa/eosago/xsl/DriverResponse2DriverStatusRequest.xsl,原因是:命名空间前缀“ns2”未声明。
无法解析端点:xslt://com/rsa/eosago/xsl/DriverResponse2DriverStatusRequest.xsl,原因是:命名空间前缀“ns2”未声明。
javax.xml.transform.TransformerConfigurationException:命名空间前缀'ns2'未声明。
为什么编译器会在以dinamically方式创建的命名空间上抛出异常?
答案 0 :(得分:0)
这非常令人困惑。为什么你不能简单地做:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="RSA-InsurerID"/>
<xsl:param name="EOSAGO-schema-version"/>
<xsl:template match="/*">
<xsl:element name="rsa:DriverStatusRequest" namespace="com/rsa/eosago/schema-{$EOSAGO-schema-version}">
<InsurerID>
<xsl:value-of select="$RSA-InsurerID"/>
</InsurerID>
<IDCheckDriver>
<xsl:value-of select="IDCheckDriver"/>
</IDCheckDriver>
</xsl:element>
</xsl:template>
</xsl:stylesheet>