【发布时间】:2018-02-16 10:39:20
【问题描述】:
我想使用 xsltproc(或我可以在 Bash 中使用的任何其他工具)从播客提要中提取 URL。有以下两种类型的 XML 提要。
A型
<rss xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>Podcast</title>
<item>
<title>Episode</title>
<media:content url="http://example.org/example.mp3" fileSize="1234" type="audio/mpeg"/>
</item>
</channel>
</rss>
B型
<rss>
<channel>
<title>Podcast</title>
<item>
<title>Episode</title>
<guid>episode::x</guid>
<enclosure type="image/jpeg" url="http://example.org/coverart.jpg"/>
<enclosure type="audio/mpeg" url="http://example.net/audio.mp3"/>
</item>
</channel>
</rss>
我有以下样式表,它返回类型 B 的 URL,但不返回类型 A 的 URL。我什至可以将这两者混合在一个样式表中吗?
<?xml version="1.0"?>
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
<output method="text"/>
<template match="/">
<for-each select = "rss/channel/item/enclosure">
<value-of select="@url"/><text> </text>
</for-each>
<for-each select = "rss/channel/item/media">
<value-of select="@url"/><text> </text>
</for-each>
</template>
</stylesheet>
【问题讨论】: