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

Re: How to split a relative link into 2 parts?

Subject: Re: How to split a relative link into 2 parts?
From: me@xxxxxxxxxxxx
Date: Wed, 21 May 2003 11:07:48 -0700 (PDT)
split utf 8
> I need to split a relative link (like:
> /careers/pages/en/index.htm) 
> into 2 parts using XSL. The first part I want to have
> within a variable 
> would be like this: /careers/pages/en (this is the
> folderpath)
> I would also like to save the second part inside a
> variabel, this would 
> look like: index.htm (this is the filename)
> 
> The link (/careers/pages/en/index.htm) would be send
to
> a template 
> (using xsl:call-template) as a parameter. The template
> that is called 
> needs to handle this string and split it in two.
> 
> I hope someone will be able to help me with this.

Somthing like this?

xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE root [
	<!ELEMENT root ( #PCDATA ) >
]>
<root>/careers/pages/en/index.htm</root>

xslt:
<?xml version="1.0" encoding="utf-8"?>
<!--
	Author: 
	File: 
	Date: 
	Purpose: 
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" indent="yes"
encoding="UTF-8"/>
	
	<xsl:template match="/">
		<xsl:call-template name="getFileName">
			<xsl:with-param name="path" select="/root" />
		</xsl:call-template>
	</xsl:template>
	
	<xsl:template name="getFileName">
		<xsl:param name="path" select="''" />
		
		<xsl:variable name="s_filename">
		<xsl:call-template name="_breaker">
			<xsl:with-param name="str" select="$path" />
		</xsl:call-template>
		</xsl:variable>
		
		<xsl:value-of select="$s_filename" /> <br/>
		<xsl:value-of
select="substring-before($path,$s_filename)"/><br/>
		
	</xsl:template>
	
	<xsl:template name="_breaker">
		<xsl:param name="str" select="''" />
		
		<xsl:variable name="strpart"
select="substring-after($str,'/')" />
		
		<xsl:if test="not(contains($strpart,'/'))">
			<xsl:value-of select="$strpart" />
		</xsl:if>
		
		<xsl:if test="contains($strpart,'/')">
			<xsl:call-template name="_breaker">
				<xsl:with-param name="str" select="$strpart" />
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	
</xsl:stylesheet>

Cheers,
Rob

    _/  _/_/    _/_/_/
   _/_/   _/ _/     _/
  _/               _/
 _/             _/
_/          _/_/_/_/
http://treebeard.sourceforge.net
http://ashpool.sourceforge.net

 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.