I’ve never used xmlstarlet so I’m just going to keep it simple with input and desired output, and hopefully I can learn something from the answers that are posted.
Input:
<channel>
<title>
<link>http://www.MYDOMAIN.com/</link>
<description></description>
<ttl>60</ttl>
<category>Sports</category>
<item>
<sport><![CDATA[Women's Soccer]]></sport>
<opponent><![CDATA[South Carolina (Exhibition)]]></opponent>
<location><![CDATA[Columbia, S.C.]]></location>
<date>08/09/2012</date>
<time>7:00 PM</time>
<tv><![CDATA[]]></tv>
<tournamentname><![CDATA[]]></tournamentname>
<homeaway>A</homeaway>
</item>
<item>
<sport><![CDATA[Men's Soccer]]></sport>
<opponent><![CDATA[Ohio State (Exhibition)]]></opponent>
<location><![CDATA[Fort Wayne, Ind.]]></location>
<date>08/17/2012</date>
<time>7:00 PM</time>
<tv><![CDATA[]]></tv>
<tournamentname><![CDATA[]]></tournamentname>
<homeaway>H</homeaway>
</item>
<item>
<sport><![CDATA[Women's Soccer]]></sport>
<opponent><![CDATA[William and Mary]]></opponent>
<location><![CDATA[Williamsburg, Va.]]></location>
<date>08/17/2012</date>
<time>7:00 PM</time>
<tv><![CDATA[]]></tv>
<tournamentname><![CDATA[]]></tournamentname>
<homeaway>A</homeaway>
</item>
Desired output:
Women's Soccer Away @ South Carolina (Exhibition) at 7:00 PM
Men's Soccer Home vs Ohio State at 7:00 PM
Women's Soccer Away @ William and Mary at 7:00 PM
A few things that make this not just straightforward data manipulation
1) I’d like to remove all data that doesn’t have a <date> of the current date
2) As you can see from the desired output, I’d like for the A result of the element <homeaway> to show the text ‘Away @’ and I’d like for the H tag to show the text ‘Home vs’
Thanks so much for your help, I really appreciate it.
1 Answer