Google产品Feed XML的XSLT转换

吉尔斯·亨特(Giles Hunt)

我有一个Google产品Feed XML,我需要对其执行XSLT转换,以转换为与会员网络兼容的新格式。我可以提取标题,描述和链接,但无法弄清楚如何引用诸如g:id或g:condition之类的值。任何帮助,不胜感激。

这是源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>

这是我的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>

问题行是:

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

提前致谢

条件

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选择应该起作用。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章