Reputation: 23
Please help me. How can I get filename using XSLT 1.0 from string like this?
filestore:/722601940006/2018/02/09/file.jpg
A file can have a different name and extension. A path can have a different depth.
I tried to use regular expression and function tokenize():
<xsl:value-of select="tokenize('$file/@fh:fileRef','.*/(.*?)$')"/>
But I found out that .Net Core doesn't support XSLT 2.0
Upvotes: 2
Views: 1376
Reputation: 29062
Because you are restricted to XSLT-1.0 a recursive template is necessary. So one XSLT-1.0 solution to avoid waiting for Microsoft to respond would be
<xsl:template name="fileName">
<xsl:param name="str" />
<xsl:choose>
<xsl:when test="normalize-space(substring-after($str,'/'))">
<xsl:call-template name="fileName">
<xsl:with-param name="str" select="substring-after($str,'/')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$str" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Calling it with
<xsl:call-template name="fileName">
<xsl:with-param name="str" select="yourFileNameString" /> <!-- insert string here -->
</xsl:call-template>
emits the string
file.jpg
Upvotes: 4