これはシンプルで純粋なXSLT1.0ソリューションであり、わずか47行で構成されており、その半分は終了タグです。次の変換:
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:outputomit-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:それ以外の場合>
<xsl:call-template name = "GetFileName">
<xsl:with-param name = "pFPath"
select = "substring-after($ pFPath、'/')" />
</ xsl:call-template>
</ xsl:それ以外の場合>
</ xsl:choose>
</ xsl:template>
</ xsl:stylesheet>
提供されたソースXMLドキュメントに適用した場合:
<アイテム>
<タイトル>2008。11月23日。</title>
<link> http://www.mr1-kossuth.hu/m3u/0039c36f_3003051.m3u </ link>
<description> ........ </ description>
<pubDate>2008年11月26日水曜日00:00:00GMT</ pubDate>
</ item>
必要な結果を生成します:
<アイテム>
<タイトル>2008。11月23日。</title>
<link> http://stream001.radio.hu:8000/content/0039c36f_3003051.mp3 </ link>
<description> ........ </ description>
<pubDate>2008年11月26日水曜日00:00:00GMT</ pubDate>
</ item>
このソリューションの次の特定の機能に注意してください。
ID変換を使用およびオーバーライドするXSLTデザインパターンを使用します。
「GetFileName」という名前のテンプレートは、完全なURL(パラメーターとして渡される)から抽出され、ファイル拡張子が削除されたファイル名のみが抽出されます。これは、自分自身を再帰的に呼び出す名前付きテンプレートの良い例です。
- 目的の新しいURLの構成要素は、グローバルとして指定されます
<xsl:param>
。