Autosorting Options
rorythecheese
Posted: Monday, September 29, 2008 1:33:18 PM

Rank: Enthusiast

Joined: 2/15/2008
Posts: 40
Location: London, England
Wasnt really sure what to call this so let me try to explain better here.

Say i have a doc type called 'people' and in that is a dropdown called 'country'. So if i add a new person i can add what country they are from.

What i want is to then list all the people within each of those countries, but with the least amount of code.

Currently im having to loop through all the 'people' then 'if statement'ing the countries.. for example.

Code:
<xsl:for-each select="$currentPage/node[@nodeTypeAlias='people']">
   <xsl:if test="data[@alias='country']='UK'">
       do stuff
   </xsl:if>
   <xsl:if test="data[@alias='country']='France'">
       do stuff
   </xsl:if>
   <xsl:if test="data[@alias='country']='Germany'">
       do stuff
   </xsl:if>
    etc.....
</xsl:for-each>


As you can see if there's alot of countries then this file can get untidy, but also is not fully dynamic as anytime i may have to add a new country i'll have to add to this file a new 'if statement' to the loop.

Is there an easier more mimimal code way of doing this ?

bootnumlock
Posted: Monday, September 29, 2008 3:36:32 PM

Rank: Fanatic

Joined: 10/9/2006
Posts: 460
Location: batavia, IL
a nested for-each i think would do the trick...

for-each country
-> for-each member where memberCountry = country
---> output value
-> end for each
end for each

i think that should work -- that is the theory code... here is snippet i just used last week for cycling through FAQ with category assignment via checkbox dataType...

Code:

<div id="basic-accordian">
<xsl:for-each select="umbraco.library:GetPreValues('1097')//preValue">
    <xsl:variable name="theCat" select="."/>
    <xsl:variable name = "theNum" select="@id"/>
<xsl:choose>
    <xsl:when test="position()='1'">
        <div id="test-header" class="accordion_headings header_highlight" ><xsl:value-of select="$theCat"/></div>
    </xsl:when>
    <xsl:otherwise>
        <div id="test{$theNum}-header" class="accordion_headings" ><xsl:value-of select="$theCat"/>
        </div>
    </xsl:otherwise>
</xsl:choose>
        
<xsl:choose>
    <xsl:when test="position()='1'">
        <div id="test-content">
            <div class="accordion_child">
    <xsl:for-each select="$currentPage/node">
        <xsl:variable name="theQ" select="./data[@alias='faqQuestion']"/>
        <xsl:variable name="theA" select="./data[@alias='faqAnswer']"/>
        <xsl:variable name="curCat" select="umbraco.library:Split(./data[@alias='faqCats'],',')"/>
            
                    <xsl:for-each select="$curCat/value">
                        <xsl:if test=".= $theCat">
                            <strong><xsl:value-of select="$theQ"  disable-output-escaping="yes"/></strong><br/>
                            <xsl:value-of select="$theA"  disable-output-escaping="yes"/><br/><br/>
                        </xsl:if>
                    </xsl:for-each>
                            
    </xsl:for-each>
    </div>
    </div>

    </xsl:when>
    <xsl:otherwise>
        <div id="test{$theNum}-content">
            <div class="accordion_child">
    <xsl:for-each select="$currentPage/node">
        <xsl:variable name="theQ" select="./data[@alias='faqQuestion']"/>
        <xsl:variable name="theA" select="./data[@alias='faqAnswer']"/>
        <xsl:variable name="curCat" select="umbraco.library:Split(./data[@alias='faqCats'],',')"/>
            
                    <xsl:for-each select="$curCat/value">
                        <xsl:if test=".= $theCat">
                            <strong><xsl:value-of select="$theQ"/></strong><br/>
                            <xsl:value-of select="$theA"/><br/><br/>
                        </xsl:if>
                    </xsl:for-each>
                            
    </xsl:for-each>
    </div>
    </div>
    </xsl:otherwise>
</xsl:choose>    

</xsl:for-each>

</div>


bootnumlock - aka bob baty-barr
My Packages Site: http://packages.maliciousthinktank.com
Business Blog: http://www.maliciousthinktank.com/blog
Personal site: http://www.baty-barr.com
Level 1 Certified!
rorythecheese
Posted: Monday, September 29, 2008 4:59:35 PM

Rank: Enthusiast

Joined: 2/15/2008
Posts: 40
Location: London, England
cheers buddy, works nicely. Had no idea i could loop through a datatype. Youve just saved me hours of unnecessary work.. Applause
skooter
Posted: Friday, October 10, 2008 10:51:04 AM

Rank: Devotee

Joined: 8/7/2008
Posts: 64
Location: Denmark
I'm a bit confused about the line:
Code:
<xsl:for-each select="umbraco.library:GetPreValues('1097')//preValue">

Where would I find that ID? And why the double-slash?

I tried this. Found it in this thread: Query the text of a radiobutton list item rather than the value
Code:
<xsl:for-each select="umbraco.library:GetPreValueAsString($currentPage/data[@alias = 'employeeDepartment'])">
   <xsl:value-of select="." />
</xsl:for-each>


It doesn't throw an error on save but on the website it says:
Quote:
Error parsing XSLT file: \xslt\employees.xslt


skooter.dk (danish)
imayat12
Posted: Friday, October 10, 2008 11:50:00 AM

Rank: Addict

Joined: 7/19/2006
Posts: 670
Location: Preston, UK
skooter,

If you goto developer section data types and hover over one you will see that it has id

Regards

Ismial

Level 2 certified. If it aint broke dont fix.
skooter
Posted: Friday, October 10, 2008 12:10:07 PM

Rank: Devotee

Joined: 8/7/2008
Posts: 64
Location: Denmark
Thanks imayat12 :)

Maybe that ID should show up somewhere on the datatype page to make it more clear...? Still it would be nicer to refere to the datatype by a name.

And I guess the double-slash is a typo. Works with both single and double...

Also I found out that the xslt is casesensitive... Writing "/prevalue" instead of "/preValue" won't work :P

skooter.dk (danish)
neilf
Posted: Friday, October 10, 2008 12:55:09 PM

Rank: Devotee

Joined: 3/19/2008
Posts: 52
Location: London
Hi Skooter,

Be careful with the "//" - it might work with both in this case but the "//" does have a special meaning in Xpath (xslt query). (Just mentioning because of your comment about it being the same above - co-incidence in this case)

e.g. umbraco.library:GetXmlAll()//node would return ALL child nodes, no matter how deep below in the xml. Sometimes that's useful if you want to find every instance of a document-type no matter where it is in the site structure

Code:
umbraco.library:GetXmlAll()//node [@nodeTypeAlias='myDocumentTypeAlias']


will get all pages of type myDocumentTypeAlias, whereas

Code:
umbraco.library:GetXmlAll()/node [@nodeTypeAlias='myDocumentTypeAlias']


will only return pages of type myDocumentTypeAlias that are directly off the site root

Neil



Disclaimer:
Projectstream Ltd (UK) and its directors make no representations as to accuracy, completeness, currentness, suitability, or validity of any information provided in the Umbraco Forum and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis and is for informational purposes only.

That being said, if you think I'm mad then please tell me. Alternatively if you think I've been really helpful thats wonderful.
skooter
Posted: Friday, October 10, 2008 2:48:25 PM

Rank: Devotee

Joined: 8/7/2008
Posts: 64
Location: Denmark
Thanks neilf, great stuff :)

skooter.dk (danish)
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.