我想弄清楚一下,看看我是否正确理解这个问题。如何使用XSLT从XML文件创建RSS 2.0订阅源?
我有一个网站的XML文件,列出了该网站的所有数据。我正在尝试创建RSS 2.0供稿,以便我可以将数据供稿上传到Google产品。 XML文件有太多信息;我只想从中获取产品,并将它们放入一个更小的XML或RSS文件中,其中包含特定于Google所需的渠道和标签。
我被告知使用XSLT样式表。它会看起来像最终项目的空模板吗?
E.g.
<channel>
<product>
<othertags>
我需要一个小脚本来运行XML文件来填充最终产品吗?
什么是脚本的最简单的方法?我可以在bash中做到吗?
编辑:
我看到能够在Dreamweaver中附加XSLT样式表;有人知道吗?
NEWEDIT: 我做了更多的研究,并让XSLTPalette在OSX上工作。我用一个随机的XSLT表格测试了一小段XML文件,并得到了很好的结果。我试图创建XSLTsheet使用这些参数:
<item>
<title>
<![CDATA[titlegoeshere]]>
</title>
<description>
<![CDATA[general description with boilerplate]]>
</description>
<link>link to item page</link>
<g:condition>new</g:condition>
<g:price>19.99</g:price>
<g:product_type>Clothing, Accessories</g:product_type>
<g:image_link>linktoimage.jpg</g:image_link>
<g:payment_accepted>Visa</g:payment_accepted>
<g:payment_accepted>Mastercard</g:payment_accepted>
<g:payment_accepted>Discover</g:payment_accepted>
</item>
所有这些标签的不一定是XML文件中的名称相同,所以在看什么样的价值观后,我会放在哪里,我将如何对应两个? XML文件大约6MB,我对使用我的2GB进行处理有疑问。我应该先尝试修剪文件吗? 我从网站上一次上传的字段中得到了这些字段,但很多链接都是不正确的,因此重做,它在RSS 2.0中,所以我想我应该坚持这一点。
编辑: 这里是一个单一产品的XML文件中的摘录:
<Product Id="21082">
<Code>21082</Code>
<Description>Cute Spaghetti Strap Top</Description>
<Url>http://www.clot333333nd.com/21082.html</Url>
<Thumb><img border=0 width=53 height=70 src=http://ep.yimg33333333333333333-27706119506618_2144_317650845></Thumb>
<Picture><img border=0 width=1125 height=1500 src=http://ep.yim333333333333333306119506618_2144_207331152></Picture>
<Weight>1</Weight>
<Orderable>YES</Orderable>
<Taxable>YES</Taxable>
<Pricing>
<BasePrice>9.99</BasePrice>
<LocalizedBasePrice>9.99</LocalizedBasePrice>
<OrigPrice>24.99</OrigPrice>
<LocalizedOrigPrice>24.99</LocalizedOrigPrice>
<SalePrice>9.99</SalePrice>
<LocalizedSalePrice>9.99</LocalizedSalePrice>
</Pricing>
<Path>
<ProductRef Id="contactus" Url="http://www.clo3333333333333ctus.html">Contact Us</ProductRef>
<ProductRef Id="tops" Url="http://www.clot333333333333ps.html">Wholesale Clothing Tops</ProductRef>
</Path>
<Availability>Usually ships the next business day.</Availability>
<Caption>th bgc&lnt></b></font></p></Caption>
<OptionLists>
<OptionList name="Size">
<OptionValue>S</OptionValue>
<OptionValue>M</OptionValue>
<OptionValue>L</OptionValue>
<OptionValue>Mixed-Sizes</OptionValue>
</OptionList>
<OptionList name="Color">
<OptionValue>Blue</OptionValue>
</OptionList>
<OptionList name="Quantities">
<OptionValue>1 Piece</OptionValue>
<OptionValue>Add(+$30.89) For 12 Pieces</OptionValue>
<OptionValue>Add(+54.77) For 24 Pieces</OptionValue>
</OptionList>
</OptionLists>
</Product>
我想使它看起来像这样:
<item>
<title>
<![CDATA[titlegoeshere]]>
</title>
<description>
<![CDATA[general description with boilerplate]]>
</description>
<link>link to item page</link>
<g:condition>new</g:condition>
<g:price>19.99</g:price>
<g:product_type>Clothing, Accessories</g:product_type>
<g:image_link>linktoimage.jpg</g:image_link>
<g:payment_accepted>Visa</g:payment_accepted>
<g:payment_accepted>Mastercard</g:payment_accepted>
<g:payment_accepted>Discover</g:payment_accepted>
</item>
这里是我想要的以匹配:
<item>
<title>
<![CDATA[titlegoeshere]]> ##Description
</title>
<description>
<![CDATA[general description with boilerplate]]> ##Caption
</description>
<link>link to item page</link> ##Url
<g:condition>new</g:condition> ##always new
<g:price>19.99</g:price> ## BasePrice
<g:product_type>Clothing, Accessories</g:product_type> ##always same
<g:image_link>linktoimage.jpg</g:image_link> ## Picture
<g:payment_accepted>Visa</g:payment_accepted> ##always same
<g:payment_accepted>Mastercard</g:payment_accepted> ## always same
<g:payment_accepted>Discover</g:payment_accepted> #always same
</item>
这是我到目前为止建立的,但我得到一些错误时我尝试使用它:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xmlns:g="http://base.google.com/ns/1.0" version="1.0">
<xsl:output method="RSS 2.0" />
<xsl:template match="Description">
<title>
</title>
</xsl:template>
<xsl:template match="Caption">
<description>
</description>
</xsl:template>
<xsl:template match="Url>
<link>
</link>
</xsl:template>
<xsl:template match="Condition">
<g:condition>
</g:condition>
</xsl:template>
<xsl:template match="Picture">
<g:image_link>
</g:image_link>
</xsl:template>
</xsl:stylesheet>
而且,我可以用foreach
给每个元素保持不变的标签,如条件,付款接受,即使他们没有在原文件中的相应值?
XSLT是一种声明性语言,针对XML转换进行了优化。如果你需要为你的任务需要一个样式表,那么你应该更准确地描述它:你希望保持什么样的元素不被输入?如果您在询问如何调用某些XSLT处理器,那么您将需要提供更多的环境上下文:至少包含XSLT处理器,至少包含语言等。 – 2011-02-09 18:24:57
当您说'语言'是指XML还是RSS 2.0?如果我使用GUI来处理XSLT,是否需要涉及脚本语言?这会使过程更有效率吗? – fightermagethief 2011-02-10 09:07:31