xsl-list
[Top] [All Lists]

RE: Grouping with contains

2006-01-10 11:22:39
It looks to me as if you are partitioning the URLs into two groups. You
don't need Muenchian grouping where the number of groups is fixed and the
grouping keys (in this case a boolean: contains(., 'globalfolder')) are
known statically.

You can just write:

<table>
  <xsl:apply-templates select="R[contains(URL,'globalfolder')]"/>
</table>
<br/>
<table>
  <xsl:apply-templates select="R[not(contains(URL,'globalfolder'))]"/>
</table>   

Michael Kay
http://www.saxonica.com/


-----Original Message-----
From: Eric Baker [mailto:ericwaynebaker(_at_)gmail(_dot_)com] 
Sent: 10 January 2006 18:00
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Grouping with contains

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>
--~--





--~------------------------------------------------------------------
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>