Giles Hunt
Giles Hunt

Reputation: 531

XSLT Transformation of Google product feed xml

I have a Google Product feed XML that I need to perform an XSLT transform on to convert to a new format that is compatible with an affiliate network. I can extract title, description and link but cannot figure out how to reference values such as g:id or g:condition. Any help greatly appreciated.

Here is source XML:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
<channel>
    <item>
        <g:id>B1005778</g:id>
        <title>Butterfly Twists Eve Black Women Ballerinas</title>
        <link>http://shopping.indiatimes.com/fashion/ballerinas/butterfly-twists-eve-black-women-ballerinas/41904/p_B1005778</link>
        <g:price>1530.000 INR</g:price>
        <description>A pair of black ballerinas for women from Butterfly Twists  Made of leatherite  these stylish ballerinas are the perfect pick for all those who want to stay on the top of the style meter without hav</description>
        <g:condition>new</g:condition>
        <g:image_link>http://shopping.indiatimes.com/images/products/medium/B1005778.jpg</g:image_link>
        <g:brand>Butterfly Twists</g:brand>
        <g:product_type>Fashion</g:product_type>
        <g:google_product_category>Fashion &amp;gt; Women &amp;gt; Footwears &amp;gt; Ballerinas</g:google_product_category>
    </item>
</channel>

and here is my 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/">

<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="item">
    <item>
        <!--<omg:merchantrank>0</omg:merchantrank>-->
        <omg:pid>10091</omg:pid>
        <title><xsl:value-of select="title"/></title>
        <description><xsl:value-of select="description"/></description>
        <link><xsl:value-of select="link"/><![CDATA[?aff=in.affiliate.1230441.{aid}.shoes.aff&utm_source=OMGPM.COM1&utm_medium=dc-clicktracker&utm_campaign={aid}&utm_content=shoes]]></link>
        <omg:imageurlsmall></omg:imageurlsmall>
        <omg:imageurlmedium><xsl:value-of select="productimage"/></omg:imageurlmedium>
        <omg:imageurllarge></omg:imageurllarge>
        <omg:price><xsl:value-of select="actualprice"/></omg:price>
        <omg:currency>INR</omg:currency>

        <omg:sku><xsl:value-of select="g:id"/></omg:sku>


        <omg:startdate/>
        <!--<omg:enddate></omg:enddate>-->

        <omg:categories>
            <xsl:call-template name="itemCategories"/>
        </omg:categories>

        <omg:attributes>
                <xsl:call-template name="itemAttributes"/>
        </omg:attributes>
    </item>
</xsl:template>

The problem line is:

<omg:sku><xsl:value-of select="g:id"/></omg:sku>

Thanks in advance

Upvotes: 1

Views: 1609

Answers (2)

fred02138
fred02138

Reputation: 3361

I think you just need to add the google rss namespace to your stylesheet:

xmlns:g="http://base.google.com/ns/1.0"

Add this to the xsl:stylesheet element at the top of your stylesheet.

Upvotes: 0

condit
condit

Reputation: 10962

The g namespace needs to be declared in your stylesheet. Try changing your stylesheet element to:

<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:g="http://base.google.com/ns/1.0">

Then the g:id selection should work.

Upvotes: 1

Related Questions