Link to home
Start Free TrialLog in
Avatar of sonic1234
sonic1234Flag for Australia

asked on

Wrting an image link with an XSLT

I'm calling the following XML feed;

http://www.google.co.uk/ig/api?weather=sydney

And thanks to some great help from Gertone transforming it with the following XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>
    
    <xsl:template match="/*">
        <xsl:apply-templates select="node()"/>
    </xsl:template>

    <xsl:template match="*">
        <div>
            <xsl:attribute name="class">
                <xsl:value-of select="concat(name(),'_data')"/>
            </xsl:attribute>
            <xsl:apply-templates select="node()|@data"/>
        </div>
    </xsl:template>
    
    <xsl:template match="forecast_information|current_conditions|forecast_conditions|icon|forecast_date">
        <div>
            <xsl:attribute name="class">
                <xsl:value-of select="name()"/>
            </xsl:attribute>
            <xsl:apply-templates select="node()|@data"/>
        </div>
    </xsl:template>
    
    <xsl:template match="postal_code|latitude_e6|longitude_e6|temp_f"/>

    <xsl:template match="low | high">
        <div>
            <xsl:attribute name="class">
                <xsl:value-of select="concat(name(), '_data')"/>
            </xsl:attribute>
            <xsl:call-template name="farenheit-to-celsius">
                <xsl:with-param name="temp" select="@data"/>
            </xsl:call-template>
        </div>
    </xsl:template>
    
    <xsl:template match="*" mode="id">
        <xsl:value-of select="concat(name(),'_data')"/>
    </xsl:template>
    
    <xsl:template name="farenheit-to-celsius">
        <xsl:param name="temp"/>
        <xsl:choose>
            <xsl:when test="not(string(number($temp)) = 'NAN')">
                <xsl:value-of select="format-number(($temp - 32) * (5 div 9) , '##.0')"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$temp"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

Open in new window


For the node where it renders

<div class="icon">/ig/images/weather/mostly_sunny.gif</div>

Open in new window


I'd like it to render

<div class="icon"><img src="/myfolderpath/ig/images/weather/mostly_sunny.gif"></div>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
maybe you need to explicitely set the output method to html

XSLT needs to be wellformed (hence the element closing for <img/>)

XML : <img ... />

html doesn't want that

HTML : <img ... >

set the method to html to get around that

   <xsl:output indent="yes"/>
becomes
   <xsl:output indent="yes" method="html"/>
Avatar of sonic1234

ASKER

Top class help Gertone, your clear code is helping me learn how this works.  Much appreciated.