XSLT - 从 URL 获取文件名 [英] XSLT - Get file name from URL
本文介绍了XSLT - 从 URL 获取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从 URL 获取文件名,URL 是动态的,斜线的数量可以是不同的数量.我正在使用 xslt 1.0,因此正在寻找需要的东西:
I need to obtain the filename from a URL, the URL is dynamic and the amount of slashes can be different amounts. Im using xslt 1.0 so looking for something that will take:
http://DevSite/sites/name/Lists/note/附件/3/image.jpg
然后给我:
图片.jpg
这在 XSLT 1.0 中可行吗?
IS this possible in XSLT 1.0?
推荐答案
如果你使用的是 xslt 2.0,你可以使用 subsequence() 并创建一个函数:
if you are using xslt 2.0, you can use subsequence() and create a function:
在 xsl:stylesheet root 中声明你的函数:
Declare your function in xsl:stylesheet root:
xmlns:myNameSpace="http://www.myNameSpace.com/myfunctions"
创建函数:
<xsl:function name="myNameSpace:getFilename">
<xsl:param name="str"/>
<!--str e.g. document-uri(.), filename and path-->
<xsl:param name="char"/>
<xsl:value-of select="subsequence(reverse(tokenize($str, $char)), 1, 1)"/>
</xsl:function>
调用函数:
<xsl:value-of select="myNameSpace:getFilename('http://DevSite/sites/name/Lists/note/Attachments/3/image.jpg', '/')"/>
这篇关于XSLT - 从 URL 获取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文