Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 555
  • Last Modified:

XSLT: Substring filename

We've a complete filepath:

file://filer12/group/IT/MCU/css/initialize_ns4.css

We need to get ONLY the filename by means of XSL (initialize_ns4.css). How to?
0
go4java
Asked:
go4java
1 Solution
 
Geert BormansCommented:
Hi go4java,

you need to solve that recursively.
you can use this template "stripPath"
(I put it in a test XSL)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <xsl:call-template name="stripPath">
            <xsl:with-param name="path">c/blabla/blabla/test.xml</xsl:with-param>
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="stripPath">
        <xsl:param name="path"/>
        <xsl:choose>
            <xsl:when test="not(contains($path, '/'))"><xsl:value-of select="$path"/></xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="stripPath">
                    <xsl:with-param name="path" select="substring-after($path, '/')"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
   
</xsl:stylesheet>

Cheers!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now