Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Eddie Foreman 215 posts 288 karma points
    Jan 13, 2012 @ 14:30
    Eddie Foreman
    0

    Using keys in Old Schema

    Hi All,

    Have a 'AwardsItem' document type with a property called year.  Would like to group the items by year and thougth I'd try at using keys.  I'm using the old schema and Umbraco 4.0.4.2. 

    I have the following:

    <xsl:variable name="documentTypeAlias" select="string('AwardItem')"/>
    <xsl:key name="year" match="AwardItem" use="year" />

    <xsl:template match="/">

    <!-- The fun starts here -->
    <xsl:for-each select="$currentPage/node [@nodeTypeAlias = $documentTypeAlias and (key('year', string(./data [@alias='year'])))]">

    <xsl:value-of select="@nodeName"/>
    </xsl:for-each>
    ...

    Been a while since I've used the old schema version version, so not sure of the syntax required for using keys.

    Example XML:

    <node id="1938" version="6cc4b9eb-b8c4-4251-9097-698265b01a43" parentID="1934" level="3" writerID="0" creatorID="0" nodeType="1935" template="0" sortOrder="1" createDate="2012-01-13T11:09:44" updateDate="2012-01-13T13:27:52" nodeName="Eurohedge Awards 2011" urlName="eurohedge-awards-2011" writerName="Administrator" creatorName="Administrator" nodeTypeAlias="AwardItem" path="-1,1057,1934,1938">
    <data alias="caption">Nominee for the</data>
    <data alias="summary"><![CDATA[Best CMS]]></data>
    <data alias="class">Nominee</data>
    <data alias="fundName">Umbraco Fund</data>
    <data alias="year">2011</data>
    <data alias="image">1937</data>
    </node>

    Thanks,
    Eddie

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 13, 2012 @ 14:44
    Lee Kelleher
    101

    Hi Eddie,

    Try this...

    <xsl:key name="year" match="node[@nodeTypeAlias = 'AwardItem']" use="data[@alias = 'year']" />

    The "match" is matching against all nodes that have an alias of "AwardItem", using the "year" property as the index.

    Cheers, Lee.

  • Eddie Foreman 215 posts 288 karma points
    Jan 13, 2012 @ 15:32
    Eddie Foreman
    0

    Hi Lee,

    Much appericated and thanks for the quick response.

    Finshed xslt below - just incase anyone needs a similiar solution to group items by year.

    <xsl:variable name="documentTypeAlias" select="string('AwardItem')"/>
    <xsl:key name="year" match="node[@nodeTypeAlias = 'AwardItem']" use="data[@alias = 'year']" />

    <xsl:template match="/">
       
        <xsl:for-each select="$currentPage/node [@nodeTypeAlias = $documentTypeAlias and generate-id() = generate-id(key('year', string(./data [@alias='year']))[1])]">
            <xsl:variable name="curYr" select="./data [@alias='year']" />
            <div class="awards-group">
                <h2>
                    <xsl:value-of select="$curYr"/>
                </h2>
                <xsl:for-each select="$currentPage/node [@nodeTypeAlias = $documentTypeAlias and string(./data [@alias='year']) = $curYr]">
                    <div class="awards-wrap">
                        <xsl:attribute name="class">
                            <xsl:choose>
                                <xsl:when test="position() mod 2 = 0">
                                    awards-wrap alt
                                </xsl:when>
                                <xsl:otherwise>
                                    awards-wrap
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                        <h3>
                            <xsl:value-of select="./data [@alias = 'class']" />
                        </h3>
                        <div class="info-block">
                            <xsl:value-of select="./data [@alias = 'summary']" />
                        </div>
                        <div class="fund-block">
                            <p>
                                <xsl:value-of select="./data [@alias = 'fundName']" />
                            </p>
                        </div>
                    </div>
                </xsl:for-each>
            </div>
        </xsl:for-each>

    </xsl:template>

    Thanks,

    Eddie

Please Sign in or register to post replies

Write your reply to:

Draft