Subject: [xsl] Re: Get file name without path info From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Fri, 8 Mar 2002 11:49:40 -0800 (PST) |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Mysterious appearance of , Diamond, Jason | Thread | [xsl] XML->XSL-> FO->PDF whitespace, Michael Engelhart |
RE: [xsl] Mysterious appearance of , Diamond, Jason | Date | RE: [xsl] Mysterious appearance of , Julian Reschke |
Month |