XSL media:content - 在XSLT中修剪字符串

CLi*_*own 2 xslt

任何人都可以告诉我如何从这里选择URL:

<media:content url="http://feedproxy.google.com/~r/TEDTalks_video/~5/aZWq6PY05YE/TimBrown_2009G.mp4" fileSize="57985745" type="video/mp4" />
Run Code Online (Sandbox Code Playgroud)

我想要:

  1. 创建此文件的链接:

  2. 修剪网址:

    http://feedproxy.google.com/~r/TEDTalks_video/~5/aZWq6PY05YE/TimBrown_2009G.mp4

至:

TimBrown_2009G
Run Code Online (Sandbox Code Playgroud)

然后采取:TimBrown_2009G并将其用作URL的一部分

Juk*_*nen 6

选择URL.您只需要确保拥有正确的命名空间URI.

<xsl:value-of xmlns:media="http://search.yahoo.com/mrss/" 
              select="media:content/@url"/>
Run Code Online (Sandbox Code Playgroud)

修剪网址.如何做到这一点取决于您使用的是XSLT 1还是2,因为后者具有更好的XPath 2.0字符串处理功能.

如果您使用的是XSLT 1,则可能需要创建一个帮助程序模板以从分隔的字符串中返回最后一个段:

<xsl:template name="last-substring-after">
  <xsl:param name="string"/>
  <xsl:param name="separator"/>
  <xsl:choose>
    <xsl:when test="contains($string, $separator)">
      <xsl:call-template name="last-substring-after">
        <xsl:with-param name="string"
                        select="substring-after($string, $separator)"/>
        <xsl:with-param name="separator"
                        select="$separator"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$string"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

然后,您可以使用它来提取URL的最后一段,然后继续在点之前提取零件.假设URL在变量中url:

<xsl:variable name="name">
  <xsl:call-template name="last-substring-after">
    <xsl:with-param name="string" select="$url"/>
    <xsl:with-param name="separator" select="'/'"/>
  </xsl:call-template>
</xsl:variable>
<xsl:value-of select="substring-before($name, '.')"/>
Run Code Online (Sandbox Code Playgroud)