Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 11th, 2005, 06:53 AM
Authorized User
 
Join Date: Mar 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Olaf_l
Default How to remove path

I have, for example, this string
'c:/programm/file/test.txt'

How do I remove the path of test.txt. All that should remain is 'test.txt'.

I tried the function substring-after like this
Code:
                    <afbeelding>
                        <xsl:variable name="bestand" select="image_reference"/>
                        <xsl:value-of select="substring-after($bestand,'/')"/>
                    </afbeelding>
but this removes everything after the first appearance of '/'. Is it possible to delete everything before the last '/' ??

 
Old April 11th, 2005, 07:03 AM
Authorized User
 
Join Date: Jul 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use a recursive template:

<xsl:template name="getFilename">
    <xsl:param name="filePath" />

    <xsl:variable name="rest-of" select="substring-after($filePath, '/')" />

    <xsl:choose>
        <xsl:when test="contains($rest-of, '/')">
            <xsl:call-template name="getFilename">
                <xsl:with-param name="filePath" select="$rest-of" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$rest-of" />
        </xsl:otherwise>
    </xsl:choose>

</xsl:template>


 
Old April 11th, 2005, 07:13 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 1.0, use a recursive template.

In XSLT 2.0, use

    tokenize($filename, '/')[last()]



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 25th, 2005, 04:19 AM
Authorized User
 
Join Date: Mar 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Olaf_l
Default

I tried this code for tokenizing, but it doesn't work. Can someone take a look at this code??

Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">
....
<image>
   <xsl:value-of select="tokenize('image_reference, '/')[last()]" />
</image>
TIA

 
Old April 25th, 2005, 11:15 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

tokenize('
         ^

you haven't closed this opening quote.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 25th, 2005, 11:16 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

By the way, saying that something "doesn't work" isn't very helpful. Tell us what output you expected and what output you actually got.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 26th, 2005, 03:58 AM
Authorized User
 
Join Date: Mar 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Olaf_l
Default

My apologies

I use now this (partial) code

Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
......

<image>
   <xsl:value-of select="tokenize('image_reference', '/')[last()]" />
</image>
The error that is given is:
'Tokenize is not a valid XSLT or XPATH function.
-->tokenize('image_reference', '/')<-- [last()]


An example of what I want is this:
The string:
'C:/Program Files/Adlib/data/afbeeldingen/0135.jpg'
Must become
'0135.jpg' or '/0135.jpg'

 
Old April 26th, 2005, 04:06 AM
Authorized User
 
Join Date: Apr 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi!

 tokenize is a keyword available only in xslt version "2.0" But you are using the version="1.0", so change to version="2.0" and then try again
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


Regards
Seetharaman





 
Old April 26th, 2005, 04:12 AM
Authorized User
 
Join Date: Mar 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Olaf_l
Default

The 1.0 is in the <xml> tag. The xsl-tag is already version 2.0.

Should i attach another namespace perhaps ?

 
Old April 26th, 2005, 04:19 AM
Authorized User
 
Join Date: Apr 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi!

Now Try this!

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:Str="http://">

<xsl:template match="/">
        <xsl:variable name="t" select="'c:\\test\\out.txt'"/>
        <xsl:value-of select="tokenize($t, '\\')[last()]"/>
</xsl:template>

</xsl:stylesheet>







Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help with path for loading Pics (app.path) Tabbasum Beginning VB 6 2 November 15th, 2007 04:57 AM
Implementing the all-path shortest path problem bitwords XSLT 1 December 6th, 2006 11:37 AM
using app.path in database path and filename kd8con VB Databases Basics 2 October 25th, 2006 11:45 AM
Convert logical path to absolute path zoostar J2EE 1 April 15th, 2005 10:36 AM
How to remove ? abdusalam Javascript How-To 1 July 27th, 2004 01:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.