Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    May 24, 2011 @ 14:14
    Anthony Candaele
    0

    sorting links per country in xslt

    Hi,

    I'm currently implementing a Links page. The links shoud be listed and sorted by country.

    Therefore I created a Link Item document type, and I created a linkCountry datatatype of type uComponent Country Picker.

    Does anyone know how I can list the links per country?

    Something like this:

    Egypt
     link 1
     link 2
     link 3

    Iran
     link 1
     link 2
     link3

    etc...

    I already created a for-each loop that loops through alll links, but now I need to implement the sort by country

    Does anyone knows how to do this with Xslt ?

    Thanks for your help,

    Anthony Candaele
    Belgium

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 24, 2011 @ 23:23
    Jan Skovgaard
    1

    Hi Anthony

    What does your current XSLT file look like?

    Maybe you need to use the muenchian method to do this...but let's see what the current XSLT looks like and then it will be much more easy to guide you in the right direction. It can be done for sure :-)

    /Jan

  • Anthony Candaele 1197 posts 2049 karma points
    May 25, 2011 @ 10:27
    Anthony Candaele
    0

    Hi Jan,

    I tried to delete this post, because I forgot to include the Xslt I was working on, but editing that post to include the Xslt generated an xslt error. I noticed that currently no forum posts can be edited on the our.umbraco.org forum

    But deleting this forum also didn't work.

    I created another forum post, this time with the xslt code included.

    I got help from Tom Fulton, which solved the problem. He also suggested to take a look in the muenchan methods. The Xslt code he provided me looks like this:

    <xsl:key name="country" match="Link [@isDoc]" use="linkCountry"/> 
       
    <xsl:template match="/">
      <xsl:apply-templates select="$currentPage/Link [generate-id() = generate-id(key('country', linkCountry)[1])]" mode="country"/>
    </xsl:template>

    <xsl:template match="Link [@isDoc]" mode="country">
      <h2><xsl:value-of select="linkCountry"/></h2>
      <xsl:apply-templates select="$currentPage/Link [linkCountry = current()/linkCountry]" mode="link"/>
    </xsl:template>
       
    <xsl:template match="Link [@isDoc]" mode="link">
      - <xsl:value-of select="@nodeName"/><br/>
    </xsl:template>

    That code perfectly works for the scenario I tried to implement. I just had to add some markup and some <xsl:if> statements to conditionally show output:

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:key name="country" match="LinkItem [@isDoc]" use="linkCountry"/>
    <xsl:param name="currentPage"/>

    <xsl:template match="/">
      <xsl:apply-templates select="$currentPage/LinkItem [generate-id() = generate-id(key('country', linkCountry)[1])]" mode="country"/>
    </xsl:template>

    <xsl:template match="LinkItem [@isDoc]" mode="country">
    <h2><xsl:value-of select="linkCountry"/></h2>
    <xsl:apply-templates select="$currentPage/LinkItem [linkCountry = current()/linkCountry]" mode="link"/>
    </xsl:template>

    <xsl:template match="LinkItem [@isDoc]" mode="link">
      <p class="tekst"><a href="{linkUrl}" class="tekstLink" title="{linkTitle}">
      <xsl:if test="linkTarget = 'Open link in new window'">
         <xsl:attribute name="target">_blank</xsl:attribute>
      </xsl:if>    
      <xsl:value-of select="linkTitle"/>  
      </a></p>
      <p class="tekst"><xsl:value-of select="linkDescription"/></p>
    </xsl:template>

Please Sign in or register to post replies

Write your reply to:

Draft