我正在使用带有Saxon插件的Eclipse Kepler。使用以下输入XML和以下XSL。任何想法我做错了什么?
我的输入XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="weathertbos.xsl" ?>
<GetCityWeatherByZIPResponse xmlns="http://ws.cdyne.com/WeatherWS/">
<GetCityWeatherByZIPResult>
<Success>true</Success>
<ResponseText>City Found</ResponseText>
<State>FL</State>
<City>Clearwater</City>
<WeatherStationCity>Clearwater</WeatherStationCity>
<WeatherID>14</WeatherID>
<Description>Cloudy</Description>
<Temperature>73</Temperature>
<RelativeHumidity>90</RelativeHumidity>
<Wind>NE10</Wind>
<Pressure>30.07R</Pressure>
<Visibility />
<WindChill />
<Remarks />
</GetCityWeatherByZIPResult>
</GetCityWeatherByZIPResponse>
我的XSL:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:max="http://www.ibm.com/maximo" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:weat="http://ws.cdyne.com/WeatherWS/" exclude-result-prefixes="soapenv max">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<max:SyncWEATHERRSPOS xmlns:max="http://www.ibm.com/maximo">
<max:WEATHERRSPOSSet>
<max:WEATHER action="AddChange">
<max:SUCCESS>
<xsl:value-of select="Success" />
</max:SUCCESS>
<max:RESPONSETEXT>
<xsl:value-of select="ResponseText" />
</max:RESPONSETEXT>
<max:STATE>
<xsl:value-of select="State" />
</max:STATE>
<max:CITY>
<xsl:value-of select="City" />
</max:CITY>
<max:WEATHERSTATIONCITY>
<xsl:value-of select="WeatherStationCity" />
</max:WEATHERSTATIONCITY>
<max:WEATHERID>
<xsl:value-of select="WeatherID" />
</max:WEATHERID>
<max:DESCRIPTION>
<xsl:value-of select="Description" />
</max:DESCRIPTION>
<max:TEMPERATURE>
<xsl:value-of select="Temperature" />
</max:TEMPERATURE>
<max:RELATIVEHUMIDITY>
<xsl:value-of select="RelativeHumidity" />
</max:RELATIVEHUMIDITY>
<max:WIND>
<xsl:value-of select="Wind" />
</max:WIND>
<max:PRESSURE>
<xsl:value-of select="Pressure" />
</max:PRESSURE>
<max:VISIBILITY>
<xsl:value-of select="Visibility" />
</max:VISIBILITY>
<max:WINDCHILL>
<xsl:value-of select="WindChill" />
</max:WINDCHILL>
<max:REMARKS>
<xsl:value-of select="Remarks" />
</max:REMARKS>
</max:WEATHER>
</max:WEATHERRSPOSSet>
</max:SyncWEATHERRSPOS>
</xsl:template>
</xsl:stylesheet>
我的输出:
<?xml version="1.0" encoding="UTF-8"?>
<max:SyncWEATHERRSPOS xmlns:weat="http://ws.cdyne.com/WeatherWS/" xmlns:max="http://www.ibm.com/maximo">
<max:WEATHERRSPOSSet>
<max:WEATHER action="AddChange">
<max:SUCCESS />
<max:RESPONSETEXT />
<max:STATE />
<max:CITY />
<max:WEATHERSTATIONCITY />
<max:WEATHERID />
<max:DESCRIPTION />
<max:TEMPERATURE />
<max:RELATIVEHUMIDITY />
<max:WIND />
<max:PRESSURE />
<max:VISIBILITY />
<max:WINDCHILL />
<max:REMARKS />
</max:WEATHER>
</max:WEATHERRSPOSSet>
</max:SyncWEATHERRSPOS>
期望的输出:
<?xml version="1.0" encoding="UTF-8"?>
<max:SyncWEATHERRSPOS xmlns:weat="http://ws.cdyne.com/WeatherWS/" xmlns:max="http://www.ibm.com/maximo">
<max:WEATHERRSPOSSet>
<max:WEATHER action="AddChange">
<max:SUCCESS>true</max:SUCCESS>
<max:RESPONSETEXT>City Found</max:RESPONSETEXT>
<max:STATE>FL</max:STATE>
<max:CITY>Clearwater</max:CITY>
<max:WEATHERSTATIONCITY>Clearwater</max:WEATHERSTATIONCITY>
<max:WEATHERID>14</max:WEATHERID>
<max:DESCRIPTION>Cloudy</max:DESCRIPTION>
<max:TEMPERATURE>73</max:TEMPERATURE>
<max:RELATIVEHUMIDITY>90</max:RELATIVEHUMIDITY>
<max:WIND>NE10</max:WIND>
<max:PRESSURE>30.07R</max:PRESSURE>
<max:VISIBILITY />
<max:WINDCHILL />
<max:REMARKS />
</max:WEATHER>
</max:WEATHERRSPOSSet>
</max:SyncWEATHERRSPOS>
我尝试了几个选项,例如:
<max:SUCCESS>
<xsl:value-of select="/GetCityWeatherByZIPResponse/GetCityWeatherByZIPResult/Success"/>
</max:SUCCESS>
使用:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:max="http://www.ibm.com/maximo" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:weat="http://ws.cdyne.com/WeatherWS/" exclude-result-prefixes="soapenv max">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:template match="GetCityWeatherByZIPResponse">
<xsl:apply-templates select="GetCityWeatherByZIPResult" />
</xsl:template>
<xsl:template match="GetCityWeatherByZIPResult">
<max:SyncWEATHERRSPOS xmlns:max="http://www.ibm.com/maximo">
<max:WEATHERRSPOSSet>
<max:WEATHER action="AddChange">
<max:SUCCESS>
<xsl:value-of select="Success" />
</max:SUCCESS>
<max:RESPONSETEXT>
<xsl:value-of select="ResponseText" />
</max:RESPONSETEXT>
<max:STATE>
<xsl:value-of select="State" />
</max:STATE>
<max:CITY>
<xsl:value-of select="City" />
</max:CITY>
<max:WEATHERSTATIONCITY>
<xsl:value-of select="WeatherStationCity" />
</max:WEATHERSTATIONCITY>
<max:WEATHERID>
<xsl:value-of select="WeatherID" />
</max:WEATHERID>
<max:DESCRIPTION>
<xsl:value-of select="Description" />
</max:DESCRIPTION>
<max:TEMPERATURE>
<xsl:value-of select="Temperature" />
</max:TEMPERATURE>
<max:RELATIVEHUMIDITY>
<xsl:value-of select="RelativeHumidity" />
</max:RELATIVEHUMIDITY>
<max:WIND>
<xsl:value-of select="Wind" />
</max:WIND>
<max:PRESSURE>
<xsl:value-of select="Pressure" />
</max:PRESSURE>
<max:VISIBILITY>
<xsl:value-of select="Visibility" />
</max:VISIBILITY>
<max:WINDCHILL>
<xsl:value-of select="WindChill" />
</max:WINDCHILL>
<max:REMARKS>
<xsl:value-of select="Remarks" />
</max:REMARKS>
</max:WEATHER>
</max:WEATHERRSPOSSet>
</max:SyncWEATHERRSPOS>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:1)
这是一个名称空间问题;标记GetCityWeatherByZIPResponse
被分配了名称空间uri http://ws.cdyne.com/WeatherWS/ ,您需要将标记与已在样式表的根目录中声明的前缀weat
匹配。
你需要修改你的样式表,如果我采取你发布的最后一次尝试(请注意你的样式表已被删节以尽可能简短地回答,完整的XSL是here):
<xsl:template match="weat:GetCityWeatherByZIPResponse">
<xsl:apply-templates select="weat:GetCityWeatherByZIPResult" />
</xsl:template>
<xsl:template match="weat:GetCityWeatherByZIPResult">
<max:SyncWEATHERRSPOS xmlns:max="http://www.ibm.com/maximo">
<max:WEATHERRSPOSSet>
<max:WEATHER action="AddChange">
<max:SUCCESS>
<xsl:value-of select="weat:Success" />
</max:SUCCESS>
<max:RESPONSETEXT>
<xsl:value-of select="weat:ResponseText" />
</max:RESPONSETEXT>
<!-- and so on ... -->
</max:WEATHER>
</max:WEATHERRSPOSSet>
</max:SyncWEATHERRSPOS>
</xsl:template>
这是我的输出XML:
<?xml version="1.0" encoding="UTF-8"?>
<max:SyncWEATHERRSPOS xmlns:weat="http://ws.cdyne.com/WeatherWS/"
xmlns:max="http://www.ibm.com/maximo">
<max:WEATHERRSPOSSet>
<max:WEATHER action="AddChange">
<max:SUCCESS>true</max:SUCCESS>
<max:RESPONSETEXT>City Found</max:RESPONSETEXT>
<max:STATE>FL</max:STATE>
<max:CITY>Clearwater</max:CITY>
<max:WEATHERSTATIONCITY>Clearwater</max:WEATHERSTATIONCITY>
<max:WEATHERID>14</max:WEATHERID>
<max:DESCRIPTION>Cloudy</max:DESCRIPTION>
<max:TEMPERATURE>73</max:TEMPERATURE>
<max:RELATIVEHUMIDITY>90</max:RELATIVEHUMIDITY>
<max:WIND>NE10</max:WIND>
<max:PRESSURE>30.07R</max:PRESSURE>
<max:VISIBILITY/>
<max:WINDCHILL/>
<max:REMARKS/>
</max:WEATHER>
</max:WEATHERRSPOSSet>
</max:SyncWEATHERRSPOS>