[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Get file name without path info

Subject: Re: Get file name without path info
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 8 Mar 2002 11:49:40 -0800 (PST)
get file name
Nathan Shaw <n8_shaw at yahoo dot com> wrote:

> I am using saxon:system-id() to get the name of the
> xml file being parsed. However, as you probably know,
> Saxon returns the entire path along with the file
> name. I want to just get the file name, strip off the
> '.xml' and replace it with '_p.html'.
> 
> So, Saxon gives me this:
> file:/C:/Documents and Settings/nshaw.HQIRMS/My
> Documents/spaceresearch/newxml/general_info/what.xml
> 
> and I want to end up with this:
> what_p.html
> 
> I am feeling rather handicapped by XSL when it comes
> to doing this. I am used to having functions like
> split(), gettoken(), replace(), etc... available to
> me.
> 
> Can someone give me some guidance as to how to do this
> in XSL?

Use FXSL.

You could use a functional composition (compose-flist) of:

strReverse, str-takeWhile, str-dropWhile, strReverse

or more simply only strReverse combined with substring-after and
substring-before:

testGetFileName.xsl:
-------------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
  <xsl:import href="strReverse.xsl"/>
  
  <xsl:output method="text"/>
  
  <xsl:template match="/">
    <!-- 1. Reverse the string -->
    <xsl:variable name="vstrReversed">
	    <xsl:call-template name="strReverse">
	      <xsl:with-param name="pStr" select="string(/*)"/>
	    </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="vstrRevFileName" 
                  select="substring-after
                              (
                               substring-before($vstrReversed, '/'),
                               '.'
                               )"/>
    
    <xsl:variable name="vPartialFileName">
      <xsl:call-template name="strReverse">
	      <xsl:with-param name="pStr" select="$vstrRevFileName"/>
      </xsl:call-template>
    </xsl:variable>
    
    <xsl:value-of select="concat($vPartialFileName, '_p.html')"/>
  </xsl:template>
</xsl:stylesheet>


When the above transformation is applied on the following source xml
document:

<text>file:/C:/Documents and
Settings/nshaw.HQIRMS/MyDocuments/spaceresearch/newxml/general_info/what.xml</text>


The result is:
what_p.html


Hope this helped.

Cheers,
Dimitre Novatchev.




__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.