I am trying to get a little clarification to see if I am understanding this problem correctly.
I have an XML file from a website that lists all data from that site. I am trying to create a RSS 2.0 feed so that I can upload a data feed to Google products. The XML file has too much info; I just want to take the products from it and put them into a smaller XML or RSS file with channels and tags specific to what Google wants.
I was told to use an XSLT stylesheet. Will it just look like an empty template of the final project?
E.g.
< channel >
< product >
< othertags >
Will I need a small script to run on the XML file to populate the final product?
What would be the easiest way to script this? Could I do it in bash?
EDIT:
I am seeing the ability to attach XSLT stylesheets in Dreamweaver; does anyone know about this?
NEWEDIT: I did more research and got XSLTPalette to work on OSX. I tested a small piece of the XML file with a random XSLTsheet and I got good results. The XSLTsheet I am trying to create uses these parameters:
<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>
All of these tags are not necessarily the same name in the XML file, so after looking at what values I would put where, how would I correspond the two? The XML file is about 6MB and I have doubts about being able to process it with my 2GB. Should I try and trim the file first? I got the fields from a previous upload for the site, but a lot of the links were incorrect, hence the redo, it was in RSS 2.0, so I imagine I should stick with that.
EDIT: Here is an excerpt of a single product in the XML file:
<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>
I would like to make it look like this:
<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>
Here is how I want it to match up:
<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>
Here is what I've built so far, but I am getting a few errors when I try to use it:
<?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>
Also, could I use foreach
to give each element the tags that stay the same, such as condition, payment accepted, even if they don't have corresponding values in the original file?