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}"/>
</map:transform>
<map:serialize/>
</map:match>

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 dir1/dir2/dir3/dir4/file1.

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

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" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output indent="yes" method="xml"/>

<xsl:param name="uri"/>

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

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

</xsl:stylesheet>

result:

<uri>
<node>cocoon</node>
<node>dir1</node>
<node>dir2</node>
<node>dir3</node>
<node>dir4</node>
<node>file1</node>
</uri>

Regards,

Joerg

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="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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Verzonden: woensdag 20 november 2002 19:06
Aan: [EMAIL PROTECTED]
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 <[EMAIL PROTECTED]> 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

---------------------------------------------------------------------
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:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to