谷歌产品饲料XML的XSLT转换(XSLT Transformation of Google pro

2019-10-18 11:58发布

我有一个谷歌产品饲料XML,我需要执行XSLT转换上转换为新的格式与联属网络兼容。 我可以提取标题,描述和链接,但不能找出如何引用值,例如克:ID或g:条件。 任何帮助极大的赞赏。

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

提前致谢

Answer 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选择应该工作。



Answer 2:

我想你只需要谷歌的RSS命名空间添加到您的样式表:

的xmlns:G = “http://base.google.com/ns/1.0”

在样式表的顶部样式表元素:这个添加到了xsl。



文章来源: XSLT Transformation of Google product feed xml