cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alten, Jelle Paul (uto)" <jelle.paul.al...@ordina.nl>
Subject RE: URI parts extraction
Date Thu, 21 Nov 2002 11:10:13 GMT
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="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

    <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: cummingscs@netscape.net [mailto:cummingscs@netscape.net]
> Verzonden: woensdag 20 november 2002 19:06
> Aan: cocoon-users@xml.apache.org
> Onderwerp: Re: URI parts extraction
> 
> 
> Yatin,
> 
> 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 <nospam@kripa.com> 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:
> >>>
> >>><uri>
> >>><node> cocoon </node>
> >>><node> dir1 </node>
> >>><node> dir2 </node>
> >>><node> dir3 </node>
> >>><node> dir4
> >>>  <leaf>file1</leaf>
> >>></node>
> >>></uri>
> >>>
> >>>[Although I do not need it, we can have 
> <hostname>,<port>,<protocol> 
> >>>tags to the xml file as well].
> >>>-Yatin
> >>>
> >>>-- 
> >>>Yatin Shah, President                       mailto:ygs@kripa.com
> >>>Kripa Inc.                                  http://www.kripa.com
> >>>Dayton, New Jersey USA                      phone:  732.329.8303

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>


Mime
View raw message