xsl-list
[Top] [All Lists]

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

2003-05-21 11:07:48
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



<Prev in Thread] Current Thread [Next in Thread>