1

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

4

2 回答 2

1

g命名空间需要在样式表中声明。尝试将您的样式表元素更改为:

<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">

然后g:id选择应该起作用。

于 2013-08-14T14:54:16.350 回答
0

我认为您只需将 google rss 命名空间添加到您的样式表中:

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

将此添加到样式表顶部的 xsl:stylesheet 元素。

于 2013-08-14T14:54:29.310 回答