Giles Hunt
Giles Hunt

Reputation: 531

Can't select from XML - not declaring namespaces in XSLT properly

Trying to run an XSLT against the following but I think I've got something wrong with the namespaces?

XML Example:

<rss version="2.0" xmlns="http://www.w3.org/ns/rex#" xmlns:mysmartprice="http://www.w3.org/2000/mysmartprice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<offers>
    <pubDate/>
    <title>ShopClues Deals Feed</title>
    <link>http://www.shopclues.com</link>
    <description>Great Deals on branded products</description>
    <language>en-gb</language>
    <offer>
        <mysmartprice:Product_Name>BreatheMaxTherapeuticPillow</mysmartprice:Product_Name>
        <mysmartprice:Price>4999.00</mysmartprice:Price>
        <mysmartprice:ourprice>4499.00</mysmartprice:ourprice>
        <mysmartprice:URL>http://www.shopclues.com/breathe-max-therapeutic-pillow.html</mysmartprice:URL>
        <mysmartprice:Prod_Image>http://cdn.shopclues.com/images/thumbnails/0/160/160/Breathe-Max-Therapeutic-P_1002001.000.CLM13218638854eca0acd18439.png</mysmartprice:Prod_Image>
        <mysmartprice:Shipping_Price>0</mysmartprice:Shipping_Price>
        <mysmartprice:Shipping_Time>5-7 working days</mysmartprice:Shipping_Time>
        <mysmartprice:Availability>Out Of Stock</mysmartprice:Availability>
        <mysmartprice:Brand>Calma</mysmartprice:Brand>
        <mysmartprice:Category>Bed Linen </mysmartprice:Category>
        <mysmartprice:SubCategory>Pillows</mysmartprice:SubCategory>
    </offer>
</offers>
</rss>

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.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:omg="http://feeds.omgadmin.co.uk/feeds/ns/1.0/" xmlns:rss="http://feeds.omgeu.com/ns/1.0/" xmlns:mysmartprice="http://www.w3.org/2000/mysmartprice">
<xsl:param name="pubDate"/>
<xsl:param name="channelTitle" select="Test"/>
<xsl:param name="channelLink"/>
<xsl:param name="channelDescription"/>
<xsl:param name="channelLanguage"/>
<xsl:param name="channelCopyright"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>
<xsl:template match="/">
<rss version="2.0">
<channel>
    <pubDate><xsl:value-of select="$pubDate"/></pubDate>
    <title><xsl:value-of select="$channelTitle"/></title>
    <link><xsl:value-of select="$channelLink"/></link>
    <description><xsl:value-of select="$channelDescription"/></description>
    <language><xsl:value-of select="$channelLanguage"/></language>
    <copyright><xsl:value-of select="$channelCopyright"/></copyright>
    <omg:processCount><xsl:value-of select="count(//product)"/>    </omg:processCount>
    <xsl:apply-templates/>      
</channel>
</rss>
</xsl:template>
<xsl:template name="itemTemplate" match="offer">
    <item>
        <!--<omg:merchantrank>0</omg:merchantrank>-->
        <omg:pid>10543</omg:pid>
        <title><xsl:value-of select="mysmartprice:Product_Name"/></title>
        <description><xsl:value-of select="mysmartprice:Product_Name"/></description>
        <link><xsl:value-of select="mysmartprice:URL"/></link>
        <omg:imageurlsmall></omg:imageurlsmall>
        <omg:imageurlmedium><xsl:value-of select="mysmartprice:Prod_Image"/></omg:imageurlmedium>
        <omg:imageurllarge></omg:imageurllarge>
        <omg:price><xsl:value-of select="mysmartprice:ourprice"/></omg:price>
        <omg:currency>INR</omg:currency>    
        <omg:sku><xsl:value-of select="mysmartprice:Product_Name"/>-    <xsl:value-of select="mysmartprice:Brand"/></omg:sku>
    </item>
</xsl:template>
</xsl:stylesheet>

I have made the namespace declaration at the top but I do not get anything back when I select the values from the XML?

Any help greatly appreciated.

Thanks in advance.

Upvotes: 0

Views: 197

Answers (1)

JLRishe
JLRishe

Reputation: 101652

offer is in the http://www.w3.org/ns/rex# namespace, so you need to declare this and use it:

xmlns:rs="http://www.w3.org/ns/rex#"



<xsl:template name="itemTemplate" match="rs:offer">

As a side note, I don't think it's very legit to tack your own namespaces onto www.w3.org with http://www.w3.org/2000/mysmartprice. You should come up with namespaces in a domain you own, or use something like tempuri.net as the domain name.

Upvotes: 2

Related Questions