xsl-list
[Top] [All Lists]

Grouping with contains

2006-01-10 10:59:57
Hi all,

I'm a *newbie* to XSLT, and while I'm an experienced Java programmer,
XSLT has challenged me more than anything else in recent memory.

I've checked the FAQ, and I haven't seen a solution to my problem, so
I thought that I'd post. I need to group items based on a the content
of a string. I've tried the Muenchian method, but very few examples
search within strings.

Given the following XML:

<ABC>
    <DEF>
        <R N="1">
            <URL>http://www.test.com/myfolder/anotherfolder/test1.htm</U>
            <RANK>10</RANK>
        </R>
        <R N="2">
            <URL>http://www.test.com/somefolder/anotherfolder/testa.htm</U>
            <RANK>10</RANK>
        </R>
        <R N="3">
            <URL>http://www.test.com/somefolder/anotherfolder/testb.htm</U>
            <RANK>10</RANK>
        </R>
        <R N="4">
            <URL>http://www.test.com/somefolder/anotherfolder/testc.htm</U>
            <RANK>10</RANK>
        </R>
        <R N="5">
            <URL>http://www.test.com/myfolder/anotherfolder/test2.htm</U>
            <RANK>10</RANK>
        </R>
    </DEF>
</ABC>

I need to produce a list where the URL containing "myfolder" are
listed first, followed by the remaining URLs, so:

<table>
<tr><td>http://www.test.com/myfolder/anotherfolder/test1.htm</td></tr>
<tr><td>http://www.test.com/myfolder/anotherfolder/test2.htm</td></tr>
</table>

<br/>

<table>
<tr><td>http://www.test.com/somefolder/anotherfolder/testa.htm</td></tr>
<tr><td>http://www.test.com/somefolder/anotherfolder/testb.htm</td></tr>
<tr><td>http://www.test.com/somefolder/anotherfolder/testc.htm</td></tr>
</table>

I've tried to build an index using the following:

<xsl:key name="myFolderIndex" match="//ABC/DEF/R"
use="URL[contains(.,'globalfolder')]"/>

and

<xsl:key name="myFolderIndex" match="//ABC/DEF/R/URL"
use="contains(.,'globalfolder')"/>

and while the XPath evaluates correctly (actually
//ABC/DEF/R/URL[contains(.,'myfolder')]), I can't seem to successfully
pull the elements out of the index.

Any help you can provide is appreciated.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



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