Subject: [xsl] RSS feed with custom additional values - how best to transform? From: Kent Nielsen <kcnsolutions@xxxxxxxxx> Date: Fri, 24 Apr 2009 14:22:29 -0500 |
Hello all, I am using Java (EE 5) using standard XSL transformer and would like to perform a relatively simple activity: take a valid RSS 2.0 feed that has some additional elements and process it using XSL to create an HTML page. Here is the feed format: <rss version="2.0" xmlns:customns="http://www.helpyoulist.com/customns"> <channel> <title>Daily listings for Acme Inc</title> <link>http://www.acmeinc.com/</link> <description>Daily listings for Acme Inc</description> <language>en-us</language> <copyright>Copyright 2009</copyright> <customns:companyName>Acme Incorporated</customns:companyName> <customns:address1>123 Main Street</customns:address1> <customns:city>Anytown</customns:city> <customns:state>NJ</customns:state> <customns:zip>12345</customns:zip> <customns:phone>(123) 555-1212</customns:phone> <customns:fax>(123) 555-1213</customns:fax> <customns:email>info@xxxxxxxxxxx</customns:email> <item> <title>2008 Acme Floor Sander</title> <guid>http://www.acmeinc.com/ACL1.html</guid> <description>What a great floor sander!</description> <customns:listingID>ACL1</customns:listingID> <customns:manufacturer>Acme</customns:manufacturer> <customns:model>FS1</customns:model> <customns:year>2008</customns:year> <customns:serial>5207</customns:serial> <customns:condition>New</customns:condition> <customns:askingPrice>519.00</customns:askingPrice> <customns:contact customns:sortOrder="1"> <customns:firstName>Raul</customns:firstName> <customns:lastName>Jones</customns:lastName> <customns:email>rjones@xxxxxxxxxxx</customns:email> <customns:phone>(123) 555-1213</customns:phone> </customns:contact> <customns:contact customns:sortOrder="2"> <customns:firstName>Brandon</customns:firstName> <customns:lastName>Boyd</customns:lastName> <customns:email>bboyd@xxxxxxxxxxx</customns:email> <customns:phone>(123) 555-1214</customns:phone> </customns:contact> </item> <item> <title>2007 Acme Belt Sander</title> <guid>http://www.acmeinc.com/ACL2556.html</guid> <description>This belt sander rules!</description> <customns:listingID>ACL2556</customns:listingID> <customns:manufacturer>Acme</customns:manufacturer> <customns:model>BS1</customns:model> <customns:year>2004</customns:year> <customns:serial>4006</customns:serial> <customns:condition>Used</customns:condition> <customns:askingPrice>299.00</customns:askingPrice> <customns:contact customns:sortOrder="1"> <customns:firstName>Brandon</customns:firstName> <customns:lastName>Boyd</customns:lastName> <customns:email>bboyd@xxxxxxxxxxx</customns:email> <customns:phone>(123) 555-1214</customns:phone> </customns:contact> <customns:contact customns:sortOrder="2"> <customns:firstName>Raul</customns:firstName> <customns:lastName>Jones</customns:lastName> <customns:email>rjones@xxxxxxxxxxx</customns:email> <customns:phone>(123) 555-1213</customns:phone> </customns:contact> </item> </channel> </rss> As you can see, it is standard RSS (and I checked! -> it's a valid RSS 2.0 feed) with some additional data within in. RSS encourages this. Here would be my XSL file: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:customns="http://www.helpyoulist.com/customns"> <xsl:output method="html" version="4.01" /> <xsl:output doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /> <xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" /> <xsl:template match="rss/channel"> <xsl:apply-templates select="item"/> </xsl:template> <xsl:template match="item"> <xsl:if test="customns:guid='http://www.acmeinc.com/ACL1.html'"> <!-- WILL REPLACE WITH VAR LATER --> <xsl:value-of select="title" /><br /> <!-- WORKS FINE! --> <xsl:value-of select="customns:model" />|<br /> <!-- IT'A NO LIKA! --> /xsl:if> </xsl:template> </xsl:stylesheet> I would consider myself a beginner to intermediate with XSL, and as such have spent about four hours reading and researching, trying to figure out how to do this. I am comfortable with other XSL concepts (looping, nodes, XPath, etc). There has been a mound of things to wade through (including the XSL 2.0 docs, which I did spend some time reading),and I am using this to get my feet wet into more advanced namespace stuff. Interestingly enough, I would think an RSS-based tutorial would be the PERFECT way to introduce namespacing. What am I missing? I've tried aliases and such to no avail.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] How to cast current-group, Studer Leo | Thread | Re: [xsl] RSS feed with custom addi, G. Ken Holman |
RE: [xsl] How to sort by elements o, Michael Kay | Date | Re: [xsl] RSS feed with custom addi, G. Ken Holman |
Month |