I am pretty new to XSLT (did one small project with it) and now I am looking to do another with XML data from a third party and I noticed they have xmlns:xsd and xmlns:xsi attributes in one of the tags. This is really throwing me off...
Other than the xmlns attributes it looks like a typical XML files I have transformed before...
1. So why would the need for those xmlns attributes arise (i.e. why are they necessary here)?
2. And how would I modify my XSL to transform the file?
-----------------
Here is the XML sent from the third party:
<?xml version="1.0" encoding="utf-8" ?>
<WeatherFeed xmlns:xsd=" xmlns:xsi=" xmlns="h
ttp://<internal>
</internal>
<Location> Alexandria, VA, United States </Location>
<RecordedAt> Alexandria, VA, United States </RecordedAt>
<Updated> 1151 AM EDT TUE JUL 20 2004 </Updated>
<Conditions> Partly Cloudy </Conditions>
<Visibility> 10 Mi </Visibility>
<Temp> 82 F </Temp>
<Humidity> 48 % </Humidity>
<Wind>N 0 MPH</Wind>
<Barometer> 29.96 in. </Barometer>
<Dewpoint> 61 F</Dewpoint>
<HeatIndex> 83 F</HeatIndex>
<WindChill> 82 F</WindChill>
<PoweredBy>Company</PoweredBy>
<Copyright> Canadian forecasts are obtained from and are copyright of Environment Canada. All other data is derived from
the NWS and other public domain sources. </Copyright>
</WeatherFeed>
-------------------
Here is my XSL which works when the xmlns:xsd attributes aren't present in the <WeatherFeed> tag:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=" version='1.0'>
<xsl:template match="/">
<html>
<head>
<title>
<xsl:value-of select='//Location'/>
</title>
</head>
<body bgcolor="blue">
<table width="100%">
<TR><td ><FONT SIZE="+3">
<xsl:for-each select="//Location">
Weather for <xsl:apply-templates select='.'/>
</xsl:for-each></FONT></td>
</TR>
<TR><td ><FONT SIZE="+2">
<xsl:for-each select="//Conditions">
Conditions: <xsl:value-of select='.'/>
</xsl:for-each></FONT></td>
</TR>
<TR><td ><FONT SIZE="+2">
<xsl:for-each select="//Temp">
Temp: <xsl:apply-templates select="."/>
</xsl:for-each></FONT></td>
</TR>
<TR><td ><FONT SIZE="+2">
<xsl:for-each select="//Barometer">
Barometer: <xsl:value-of select='.'/>
</xsl:for-each></FONT></td>
</TR>
<TR><td ><FONT SIZE="+2">
<xsl:for-each select="//PoweredBy">
<xsl:apply-templates select="."/>
</xsl:for-each></FONT></td>
</TR>
</table>
</body>
</html>
</xsl:template>
<xsl:template match='Location'>
<xsl:variable name="location">
<xsl:value-of select="."/>
</xsl:variable>
<xsl:variable name="city">
<xsl:value-of select="substring-before($location,',')"/>
</xsl:variable>
<xsl:variable name="stateAbbr">
<xsl:value-of select="substring-before(substring-after($location,','), ',')"/>
</xsl:variable>
<font color="red"><i><xsl:value-of select='$city'/>, <xsl:value-of select='$stateAbbr'/></i></font>
</xsl:template>
<xsl:template match='Temp'>
<font color="red"><i><xsl:value-of select='.'/></i></font>
</xsl:template>
<xsl:template match='PoweredBy'>
<xsl:variable name="url"><xsl:value-of select="."/></xsl:variable>
<xsl:variable name="href">
<xsl:value-of select="substring-before(substring-after($url,' '), ' ')"/>
</xsl:variable>
<a>
<xsl:attribute name="href"> select="$href"/></xsl:attribute>
<font color="white"><xsl:value-of select="$href"/></font>
</a>
</xsl:template>
</xsl:stylesheet>
TIA
Other than the xmlns attributes it looks like a typical XML files I have transformed before...
1. So why would the need for those xmlns attributes arise (i.e. why are they necessary here)?
2. And how would I modify my XSL to transform the file?
-----------------
Here is the XML sent from the third party:
<?xml version="1.0" encoding="utf-8" ?>
<WeatherFeed xmlns:xsd=" xmlns:xsi=" xmlns="h
ttp://<internal>
</internal>
<Location> Alexandria, VA, United States </Location>
<RecordedAt> Alexandria, VA, United States </RecordedAt>
<Updated> 1151 AM EDT TUE JUL 20 2004 </Updated>
<Conditions> Partly Cloudy </Conditions>
<Visibility> 10 Mi </Visibility>
<Temp> 82 F </Temp>
<Humidity> 48 % </Humidity>
<Wind>N 0 MPH</Wind>
<Barometer> 29.96 in. </Barometer>
<Dewpoint> 61 F</Dewpoint>
<HeatIndex> 83 F</HeatIndex>
<WindChill> 82 F</WindChill>
<PoweredBy>Company</PoweredBy>
<Copyright> Canadian forecasts are obtained from and are copyright of Environment Canada. All other data is derived from
the NWS and other public domain sources. </Copyright>
</WeatherFeed>
-------------------
Here is my XSL which works when the xmlns:xsd attributes aren't present in the <WeatherFeed> tag:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=" version='1.0'>
<xsl:template match="/">
<html>
<head>
<title>
<xsl:value-of select='//Location'/>
</title>
</head>
<body bgcolor="blue">
<table width="100%">
<TR><td ><FONT SIZE="+3">
<xsl:for-each select="//Location">
Weather for <xsl:apply-templates select='.'/>
</xsl:for-each></FONT></td>
</TR>
<TR><td ><FONT SIZE="+2">
<xsl:for-each select="//Conditions">
Conditions: <xsl:value-of select='.'/>
</xsl:for-each></FONT></td>
</TR>
<TR><td ><FONT SIZE="+2">
<xsl:for-each select="//Temp">
Temp: <xsl:apply-templates select="."/>
</xsl:for-each></FONT></td>
</TR>
<TR><td ><FONT SIZE="+2">
<xsl:for-each select="//Barometer">
Barometer: <xsl:value-of select='.'/>
</xsl:for-each></FONT></td>
</TR>
<TR><td ><FONT SIZE="+2">
<xsl:for-each select="//PoweredBy">
<xsl:apply-templates select="."/>
</xsl:for-each></FONT></td>
</TR>
</table>
</body>
</html>
</xsl:template>
<xsl:template match='Location'>
<xsl:variable name="location">
<xsl:value-of select="."/>
</xsl:variable>
<xsl:variable name="city">
<xsl:value-of select="substring-before($location,',')"/>
</xsl:variable>
<xsl:variable name="stateAbbr">
<xsl:value-of select="substring-before(substring-after($location,','), ',')"/>
</xsl:variable>
<font color="red"><i><xsl:value-of select='$city'/>, <xsl:value-of select='$stateAbbr'/></i></font>
</xsl:template>
<xsl:template match='Temp'>
<font color="red"><i><xsl:value-of select='.'/></i></font>
</xsl:template>
<xsl:template match='PoweredBy'>
<xsl:variable name="url"><xsl:value-of select="."/></xsl:variable>
<xsl:variable name="href">
<xsl:value-of select="substring-before(substring-after($url,' '), ' ')"/>
</xsl:variable>
<a>
<xsl:attribute name="href"> select="$href"/></xsl:attribute>
<font color="white"><xsl:value-of select="$href"/></font>
</a>
</xsl:template>
</xsl:stylesheet>
TIA