2 users online. Create an account or sign in to join them.Users

Search

Is there a way that I can group my XML results according to multiple parameters? Now I can group my XML output by one parameter. But what if I want to be able to group it by multiple parameters?

For example: I have content with parameter A and parameter B. First I want to group the content by parameter A. This is possible now. Next, I want to group each group by parameter B:

A schematic example of how i want my output to be:

A0 - B0 - content
A0 - B0 - content
A0 - B1 - content
A0 - B1 - content
A0 - B1 - content
A0 - B2 - content
A1 - B0 - content
A1 - B0 - content
A1 - B1 - content
A1 - B1 - content
A1 - B1 - content
A1 - B2 - content

I don’t see how this is possible at the moment. Or am I missing something? Or is this something I could do with XSLT?

I think you’ll only be able to group by one parameter coming out of your datasource, but yes, you should be able to use xsl:sort to further order them within those groups if you need to.

If you are comfortable writing your own SQL and PHP you can modify the grab-function in the datasource-php-file. The allowEditorToParse-function should return false then to prevent the datasource editor overwriting your changes.

I tried xsl:sort but here is my situtation: I have the following XML structure:

<menu>
    <upper value="Menu 1">
        <entry id="7">
            <title>subPage 1.1</titel>
            <category>Main</category>
        </entry>
        <entry id="8">
            <title>subPage 1.2</titel>
            <category>Main</category>
        </entry>
        <entry id="9">
            <title>subPage 1.3</titel>
            <category>Category 2</category>
        </entry>
    </upper>
</menu>

Now I wish to get the following HTML output:

<strong>Menu 1</strong>
<ul>
    <li><a href="#">subPage 1.1</a></li>
    <li><a href="#">subPage 1.2</a></li>
</ul>
<strong>Category 2</strong>
<ul>
    <li><a href="#">subPage 1.3</a></li>
</ul>

But I can’t seem to get the desired result… :(

Without having tried:

<xsl:apply-templates select="upper/entry[category != preceding-sibling::category]"/>

<xsl:template match="upper/entry">
    <strong><xsl:value-of select="category" /></strong>
    <ul>
        <xsl:apply-templates select=".[category = current()/category]" mode="items" />
    </ul>
</xsl:template>

<xsl:template match="upper/entry" mode="items">
    <li><xsl:value-of select="title" /></li>
</xsl:template>

Although this will only work if your nodeset is ordered by category.

If you can get your head around it, the Muenchian Method can be used to group items in XSLT. That’s how I do a list of articles grouped by month.

Wow perfect! This was exactly what I was looking for. It’s working now! Thanks! Now I am going to study that Muenchian Method so that I can understand what is exactly happening. There is more joy in understanding XSLT then just copy/pasting it.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.2 or above
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.0 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details