现在有一个xml文件,如下:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="SoapRouter.xslt"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dp="http://www.datapower.com/extensions" xmlns:dpquery="http://www.datapower.com/param/query" xmlns:test="http://test.ibm.com">
<SOAP-ENV:Header>
<test:Version>1.0</test:Version>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<test:findUser>
<firstName>diao </firstName>
<lastName>xiao dong</lastName>
<Version>1.0</Version>
</test:findUser>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>还有一个xslt文件,如下:
<?xml version="1.0" encoding="UTF-8"?>
<?altova_samplexml C:\Program Files\Altova\XMLSpy2006\Examples\my_lab\RouterSoapInput.xml?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://test.ibm.com">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/SOAP-ENV:Envelope/SOAP-ENV:Body/test:findUser">
<xsl:call-template name="createSoapMessage"/>
</xsl:template>
<xsl:template name="createSoapMessage" match="/SOAP-ENV:Envelope/SOAP-ENV:Body/test:findUser">
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<test:findUser>
<firstName>
<xsl:value-of select="firstName"/>
</firstName>
<lastName>
<xsl:value-of select="lastName"/>
</lastName>
</test:findUser>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</xsl:template>
</xsl:stylesheet>然后在xmlspy中把xml和xslt绑定到一起,执行转换,那么生成的结果为:
<?xml version="1.0" encoding="UTF-8"?>
1.0
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:test="http://test.ibm.com" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<test:findUser>
<firstName>diao </firstName>
<lastName>xiao dong</lastName>
</test:findUser>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
请大家注意SOAP-ENV前面的那个1.0, 我是实在不明白他是怎么生成的,希望大家能给解释下! 实际的文件中,我是不需要这个1.0的。如果有这个1.0,那么将会是个错误的soap文件。

解决方案 »

  1.   

    <SOAP-ENV:Header>
    <test:Version>1.0</test:Version>
    </SOAP-ENV:Header>
      

  2.   

    add
    <xsl:template match="/SOAP-ENV:Envelope/SOAP-ENV:head"/>
      

  3.   

    不精确,请加模板
    <xsl:template match="/SOAP-ENV:Envelope/SOAP-ENV:Header"/>“1.0”文本出现是因为xslt的默认模板起了作用,自动将漏配的Header节点中文本节点输出。
    增加上述模板是告诉引擎,对Header中的文本不要输出到结果中。