xml代码
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="MyXmlTransformer.xsl"?>
<JMO_obsList xmlns="urn:metoc:jmcbl:jmibl">
<urn:JMO_obs urn:observationTime ="20110118150000" urn:platformID="A001" urn:reporTypeCode="AUTO"
urn:HorizontalDatum="WGE" urn:verticalDatum="MSL" urn:stationMode="0"
urn:networkType="PTDS" xmlns:urn="urn:metoc:jmcbl:jmcbl:jmibl">
<JMO_surfaceObs urn:stationPressure ="998.308" urn:airTemperature="28.56"
urn:windDirection="320" urn:windSpeed="3.807"/>
<urn:JMO_precipitation urn:PrecipAmount="6.858" urn:observationPeriod="60"
urn:precipType="L" urn:occcurenceID="1"/>
</urn:JMO_obs>
</JMO_obsList>
xslt代码
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="/">
<html>
<body>
<b>METAR</b>
<br/>
<span style="color:blue">
<xsl:value-of select="JMO_obsList/JMO_surfaceObs/windSpeed"/>
</span><br/>
<span style="color:blue">
<xsl:value-of select="JMO_obsList/JMO_surfaceObs/stationPressure"/>
</span><br/>
<span style="color:blue">
<xsl:value-of select="JMO_obsList/JMO_Obs/observationTime"/>
</span><br/>
<span style="color:blue">
<xsl:value-of select="JMO_obsList/JMO_precipitation/PrecipAmount"/>
</span><br/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:0)
在样式表中,您必须为命名空间定义前缀&#34; urn:metoc:jmcbl:jmibl&#34;和urn:metoc:jmcbl:jmcbl:jmibl并使用它们显式限定对JMO_obsList和其他元素的引用。此外,对windSpeed和其他XML属性的引用需要使用属性:axis
进行引用完整的声明值的示例:
<span style="color:blue">
<xsl:value-of xmlns:ns1="urn:metoc:jmcbl:jmibl"
xmlns:ns2="urn:metoc:jmcbl:jmcbl:jmibl"
select="ns1:JMO_obsList/ns2:JMO_obs/ns1:JMO_surfaceObs/@ns2:stationPressure"/>
</span>