简体   繁体   中英

Get filename from path using XSLT 1.0 (c# .Net Core)

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM