This is a simple and pure XSLT 1.0 solution, consisting of just 47 lines, half of which are closing tags. The following transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-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:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="link">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:variable name="vFName">
<xsl:call-template name="GetFileName">
<xsl:with-param name="pFPath" select="."/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat($pNewLink,$vFName,$pNewExt)"/>
</xsl:copy>
</xsl:template>
<xsl:template name="GetFileName">
<xsl:param name="pFPath"/>
<xsl:choose>
<xsl:when test="not(contains($pFPath, '/'))">
<xsl:value-of select="substring-before($pFPath, '.')"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="GetFileName">
<xsl:with-param name="pFPath"
select="substring-after($pFPath, '/')"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
when applied on the provided source XML document:
<item>
<title>2008. november 23.</title>
<link>http://www.mr1-kossuth.hu/m3u/0039c36f_3003051.m3u</link>
<description>........</description>
<pubDate>Wed, 26 Nov 2008 00:00:00 GMT</pubDate>
</item>
produces the wanted result:
<item>
<title>2008. november 23.</title>
<link>http://stream001.radio.hu:8000/content/0039c36f_3003051.mp3</link>
<description>........</description>
<pubDate>Wed, 26 Nov 2008 00:00:00 GMT</pubDate>
</item>
Do note the following specific features of this solution:
We use the XSLT design pattern of using and overriding the identity transformation.
The template named "GetFileName" extracts from the complete URL (passed as parameter), just the filename with the file extension stripped off. This is a good example of a named template that calls itself recursively.
- The constituents of the desired new URLs are specified as global
<xsl:param>
s