Creating Lists Filtered by Template Name and Macro Variable Options
VirtualRichard
Posted: Tuesday, February 26, 2008 1:49:45 PM

Rank: Fanatic

Joined: 9/17/2007
Posts: 264
Location: London, UK.
This is a XPath problem (I think) that has me tearing my hair out...

As an example, consider I have a list of trees.

I want to separate them as conifer or deciduous - but want any examples at the same level. As such, I can't have a heirarchy:

/tree
- conifer
- deciduous
- etc.

Rather I must use:

/conifer tree
/deciduous tree
/conifer tree
/etc.

If I then want a 'trees' page that contains two lists of links, one to all conifer and one to all deciduous tree pages, what is the best way to do so?

Here's where my thoughts lead me:

Have a 'Tree' template all tree pages can use.

ListTrees.xslt with a macro containing a treetype parameter that can be 'deciduous' or 'conifer' (chosen through a custom dropdown during page creation).

I can access the parameter through:

<xsl:variable name="treetype" select="/macro/treetype"/>

I can list all tree pages by finding all the matching pages with a tree template:

<xsl:for-each select="$currentPage/ancestor-or-self::root//node [@nodeTypeAlias='Tree']">

But how do I adapt/filter that to only include Deciduous or conifer trees based on the parameter passed through? Ideally, I'd want it to be part of the for-each above.

Regards,

Richard

2 * 3 * 3 * 37 : The prime factorisation of The Beast.
rdcpro
Posted: Wednesday, February 27, 2008 7:21:23 PM
Rank: Newbie

Joined: 8/20/2007
Posts: 8
This seems like a Muenchian Grouping problem to me, if I understand what you're trying to do.

Code:

<trees>
    <tree type="Conifer">Noble Fir</tree>
    <tree type="Deciduous">Live Oak</tree>
    <tree type="Conifer">Hemlock</tree>
    <tree type="Deciduous">Ash</tree>
    <tree type="Deciduous">Alder</tree>
    <tree type="Conifer">White Pine</tree>
    <tree type="Conifer">Douglas Fir</tree>
    <tree type="Deciduous">Red Oak</tree>
    <tree type="Deciduous">Cottonwood</tree>
    <tree type="Deciduous">Hickory</tree>
</trees>


and

Code:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:key name="kTreeType" match="tree" use="@type"/>
    <xsl:param name="pTreeType">Conifer</xsl:param>
    <xsl:template match="trees">
        <xsl:for-each select="tree[generate-id() = generate-id(key('kTreeType', @type))]">
            <h1><xsl:value-of select="@type"></xsl:value-of></h1>
            <xsl:for-each select="/trees/tree[@type=current()/@type]">
                <xsl:value-of select="."/><br/>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>



yields this:

Code:


    <h1>Conifer</h1>
        Noble Fir<br/>
        Hemlock<br/>
        White Pine<br/>
        Douglas Fir<br/>
    <h1>Deciduous</h1>
        Live Oak<br/>
        Ash<br/>
        Alder<br/>
        Red Oak<br/>
        Cottonwood<br/>
        Hickory<br/>




Regards,
Mike Sharp
dawoe
Posted: Wednesday, February 27, 2008 7:31:32 PM

Rank: Aficionado

Joined: 1/19/2008
Posts: 170
Location: Belgium
Hey Mike,

How do you implement this in the following scenario.
Say that i want to make a site for a soccer team. I there have a played documenttype. On that I use a datatype with prevalues "Keeper","Defender","Midfield","Winger",etc. This datatype is a checkboxlist so multiple values can be selected.

Can I use the same xslt for rendering it in this way.

"Keeper"
Player A
Player B

"Defense"

Player C
Player D

"Defense","Midfield"
Player E

"Midfield"
Player F

"Midfield","Winger"
Player G

etc.

Cheers,

Dave



Converting a DotNetNuke site to Umbraco : Follow it here
rdcpro
Posted: Friday, February 29, 2008 6:34:38 PM
Rank: Newbie

Joined: 8/20/2007
Posts: 8
You do that with a composite key, but it's still Muenchian grouping.

Post an example of your XML for this scenario; there's several ways you can do it, depending on the XML.

Mike
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.