这是一个简单而纯粹的 XSLT 1.0 解决方案,仅包含 47 行,其中一半是结束标记。以下转换:
<xsl:stylesheet 版本="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:输出省略-xml-declaration="yes"/>
<xsl:param name="pNewLink"
select="'http://stream001.radio.hu:8000/content/'"/>
<xsl:param name="pNewExt" select="'.mp3'"/>
<xsl:template match="node()|@*">
<xsl:复制>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:模板>
<xsl:template match="链接">
<xsl:复制>
<xsl:copy-of select="@*"/>
<xsl:变量名="vFName">
<xsl:call-template name="GetFileName">
<xsl:with-param name="pFPath" select="."/>
</xsl:调用模板>
</xsl:变量>
<xsl:value-of select="concat($pNewLink,$vFName,$pNewExt)"/>
</xsl:copy>
</xsl:模板>
<xsl:template name="GetFileName">
<xsl:param name="pFPath"/>
<xsl:选择>
<xsl:when test="not(contains($pFPath, '/'))">
<xsl:value-of select="substring-before($pFPath, '.')"/>
</xsl:when>
<xsl:否则>
<xsl:call-template name="GetFileName">
<xsl:with-param name="pFPath"
select="substring-after($pFPath, '/')"/>
</xsl:调用模板>
</xsl:否则>
</xsl:选择>
</xsl:模板>
</xsl:样式表>
当应用于提供的源 XML 文档时:
<项目>
<标题>2008. 11 月 23 日。</title>
<link>http://www.mr1-kossuth.hu/m3u/0039c36f_3003051.m3u</link>
<description>........</description>
<pubDate>格林威治标准时间 2008 年 11 月 26 日星期三 00:00:00</pubDate>
</项目>
产生想要的结果:
<项目>
<标题>2008. 11 月 23 日。</title>
<link>http://stream001.radio.hu:8000/content/0039c36f_3003051.mp3</link>
<description>........</description>
<pubDate>格林威治标准时间 2008 年 11 月 26 日星期三 00:00:00</pubDate>
</项目>
请注意此解决方案的以下特定功能:
我们使用 XSLT 设计模式来使用和覆盖身份转换。
名为“GetFileName ”的模板从完整的 URL(作为参数传递)中提取,只是去掉了文件扩展名的文件名。这是递归调用自身的命名模板的一个很好的例子。
- 所需新 URL 的组成部分被指定为 global
<xsl:param>
s