cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joerg Heinicke <>
Subject Re: URI parts extraction
Date Thu, 21 Nov 2002 23:15:50 GMT
This is the solution I would prefer. To complete it a bit:

In the sitemap 2 solutions are possible:

<map:match pattern="**/*">
   <map:generate src="{2}.xml"/>
   <map:transform src="{2}.xsl">
     <map:parameter name="uri" value="{0}"/>

This would pass only the part of the URL, which is matched. So for 
example in the root sitemap from your string 
http://hostname/cocoon/dir1/dir2/dir3/dir4/file1 will be passed 

<map:match pattern="**/*">
   <map:generate src="{2}.xml"/>
   <map:act type="request">
     <map:transform src="{../2}.xsl">
       <map:parameter name="uri" value="{requestURI}"/>
   <map:serialize type="xml"/>

This would pass /cocoon/dir1/dir2/dir3/dir4/file1 independent of root or 
sub sitemap. So I prefer this solution.

If you add global param to Jelle's solution you can access this string 
and process it with his recursive template.

So at the end the stylesheet could look like:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
<xsl:output indent="yes" method="xml"/>

<xsl:param name="uri"/>

<xsl:template match="/">
     <xsl:call-template name="split-uri">
       <xsl:with-param name="str" select="substring($uri,2)"/>

<xsl:template name="split-uri">
   <xsl:param name="str"/>
     <xsl:when test="contains($str, '/')">
         <xsl:value-of select="substring-before($str,'/')"/>
       <xsl:call-template name="split-uri">
         <xsl:with-param name="str" select="substring-after($str,'/')"/>
         <xsl:value-of select="$str"/>






Alten, Jelle Paul (uto) wrote:
> Hi everybody and Yatin,
> As my first contribution to this list I thought I'd help someone... I
> included a simple stylesheet that does what you want. Hope it helps.
> Jelle
> PS I was there in Nazareth, and now I'm here too!  Woo hoo!
> --- here is the xsl ----
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl=""
> xmlns:fo="">
>     <xsl:template match="/">
>         <!-- I match on the root of the document, in this case I do nothing
> with the input document, just use it as a starting point -->
>         <!-- I just put the uri in a variable for now, as an example. It
> might be passed as a parameter or whatever instead -->
>         <xsl:variable
> name="uri">http://hostname/cocoon/dir1/dir2/dir3/dir4/file1</xsl:variable>
>         <uri>
>             <xsl:call-template name="split-uri">
>                 <!-- I'm not dealing with uppercase 'HTTP://' uris, sorry
> -->
>                 <xsl:with-param name="str"
> select="substring-after($uri,'http://')"/>
>             </xsl:call-template>
>         </uri>    
>     </xsl:template>
>     <xsl:template name="split-uri">
>         <!-- splitting the uri, pass a parameter named str which contains
> the string without the 'http://' -->
>         <xsl:param name="str"/>
>         <xsl:choose>
>             <!-- if there is some '/' still left, use the text before to
> print out the node and call myself for the rest -->
>             <xsl:when test="contains($str,'/')">
>                 <!-- make a node -->
>                 <node><xsl:value-of
> select="substring-before($str,'/')"/></node>
>                 <!-- call myself with the rest -->
>                 <xsl:call-template name="split-uri">
>                     <xsl:with-param name="str"
> select="substring-after($str,'/')"/>
>                 </xsl:call-template>
>             </xsl:when>
>             <!-- no '/' left, just make a node -->
>             <xsl:otherwise>
>                 <node><xsl:value-of select="$str"/></node>
>             </xsl:otherwise>
>         </xsl:choose>
>     </xsl:template>
> </xsl:stylesheet>
> --- end of xsl ---
>>-----Oorspronkelijk bericht-----
>>Van: []
>>Verzonden: woensdag 20 november 2002 19:06
>>Onderwerp: Re: URI parts extraction
>>You could just pass the whole URI in as one parameter and 
>>write templates that recursively extract the parts. It's a 
>>little tedious, but it can be done. I don't have an example 
> <!-- snip by Jelle -->
>>>>Yatin Shah <> wrote:
>>>>>Is there an existing component(a Matcher!) which will 
>>extract individual
>>>>>names from a URI?
>>>>>What I want is:
>>>>>Given http://hostname/cocoon/dir1/dir2/dir3/dir4/file1
>>>>>I want XML file as follows:
>>>>><node> cocoon </node>
>>>>><node> dir1 </node>
>>>>><node> dir2 </node>
>>>>><node> dir3 </node>
>>>>><node> dir4
>>>>> <leaf>file1</leaf>
>>>>>[Although I do not need it, we can have 
>>>>>tags to the xml file as well].

Please check that your question  has not already been answered in the
FAQ before posting.     <>

To unsubscribe, e-mail:     <>
For additional commands, e-mail:   <>

View raw message