Xquery 如何在Marklogic Server中获取文件扩展名?
我想在Marklogic server中获取上载文件的文件扩展名。我知道如何获取文件名。但这会给文件名加上像new.txt这样的扩展名。但我只想要扩展名,而不是完整的文件名。如何仅获取文件扩展名?从文件名获取文件扩展名的方法有很多。例如,您可以使用Xquery 如何在Marklogic Server中获取文件扩展名?,xquery,marklogic,Xquery,Marklogic,我想在Marklogic server中获取上载文件的文件扩展名。我知道如何获取文件名。但这会给文件名加上像new.txt这样的扩展名。但我只想要扩展名,而不是完整的文件名。如何仅获取文件扩展名?从文件名获取文件扩展名的方法有很多。例如,您可以使用functx:substring after last($filename,'.')或其他方法(fn:substring after)获取点后的子字符串。请参阅: 另外,从文件名获取文件扩展名的方法有很多。例如,您可以使用functx:substrin
functx:substring after last($filename,'.')
或其他方法(fn:substring after)
获取点后的子字符串。请参阅:
另外,从文件名获取文件扩展名的方法有很多。例如,您可以使用
functx:substring after last($filename,'.')
或其他方法(fn:substring after)
获取点后的子字符串。请参阅:
另外,fn:tokenize($filename,\.)[fn:last()]我经常使用以下替换:
fn:replace("c:\a\b\c.d.e.txt", '^(.*\.)?([^\.]+)$', '$2')
但正如Andrew所建议的,使用functx也是一个好主意。functx库的副本作为MarkLogic后期版本的一部分分发。只需添加以下导入即可使其可用:
import module namespace functx = "http://www.functx.com" at "/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";
嗯 我经常使用以下替换:
fn:replace("c:\a\b\c.d.e.txt", '^(.*\.)?([^\.]+)$', '$2')
但正如Andrew所建议的,使用functx也是一个好主意。functx库的副本作为MarkLogic后期版本的一部分分发。只需添加以下导入即可使其可用:
import module namespace functx = "http://www.functx.com" at "/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";
嗯 只是为了多样性,另一个产生扩展名的表达式:): 其中
反向字符串($s)
可定义为:
codepoints-to-string(reverse(string-to-code-points($s)))
所以整个替换表达式是:
codepoints-to-string(
reverse(
string-to-codepoints(
substring-before(codepoints-to-string(reverse(string-to-codepoints($filePath))),
'.')
)
)
)
仅就多样性而言,另一个产生扩展名的表达式:): 其中
反向字符串($s)
可定义为:
codepoints-to-string(reverse(string-to-code-points($s)))
所以整个替换表达式是:
codepoints-to-string(
reverse(
string-to-codepoints(
substring-before(codepoints-to-string(reverse(string-to-codepoints($filePath))),
'.')
)
)
)
这不应该是
fn:tokenize($filename,'\.')[fn:last()]
?是的,你是对的。第二个参数采用正则表达式模式。谢谢。谢谢,它就像你说的那样工作,使用let$uriExtension:=fn:tokenize($baseURI,'\.')[fn:last()]不应该是fn:tokenize($filename,'\.')[fn:last()]
?是的,你是对的。第二个参数采用正则表达式模式。谢谢。谢谢,它按照您所说的那样工作,使用let$uriExtension:=fn:tokenize($baseURI,'\.')[fn:last()]