我从来没有使用过 xmlstarlet,所以我只是通过输入和所需的输出来保持简单,希望我可以从发布的答案中学到一些东西。
输入:
<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>
期望的输出:
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
一些事情使这不仅仅是简单的数据操作
1)我想删除所有没有<date>
当前日期的数据
2)从所需的输出中可以看出,我希望元素的 A 结果<homeaway>
显示文本“Away @”,我希望 H 标签显示文本“Home vs”
非常感谢您的帮助,我真的很感激。