Copied to clipboard

Flag this post as spam?

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


  • singer777 69 posts 80 karma points
    Nov 23, 2011 @ 06:54
    singer777
    0

    Need to display nodes of a given property alias

    I have about 1,000 products on a website and I want to have a page list them - BUT - only if they meet a certain doctype alias. So for instance a page might show all Ford vehicles. So the "Manufacturer" doctype property within my 1,000 items needs to say "Ford" in order to show in my XSLT. 

    I would like to know how to do this also from the SAME level as the page that I would add the Macro onto. So they are not all child pages, they are on the same level.

    Thanks in advance for any help you can offer!

  • singer777 69 posts 80 karma points
    Dec 03, 2011 @ 16:20
    singer777
    0

    Does anyone have any tips for this? I'm pretty sure it must be something that's not too difficult to do in XSLT. Thanks in advance for your time!

  • Chriztian Steinmeier 2737 posts 8401 karma points MVP 5x admin c-trib
    Dec 03, 2011 @ 19:42
    Chriztian Steinmeier
    0

    Hi singer777,

    You're right - it's not at all difficult with XSLT. Take a look at the following for a simple approach:

    <xsl:param name="currentPage" />
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
    <xsl:template match="/">
        <!-- Any Ford at or below $currentPage (substitute $siteRoot for $currentPage to grab all Fords in entire site) -->
        <xsl:apply-templates select="$currentPage/descendant-or-self::*[@isDoc][manufacturer = 'Ford']" />
    </xsl:template>
    
    <!-- Template for any Document Type -->
    <xsl:template match="*[@isDoc]">
        <!-- do stuff -->
    </xsl:template>
    

     

    /Chriztian

  • singer777 69 posts 80 karma points
    Dec 05, 2011 @ 07:51
    singer777
    0

    Chriztian,

    Thanks so much for helping. Unfortunately I don't have it working yet. It needs to be the complete site, as you thought about...I am putting all of the "Products" in one folder in Umbraco, so that they are easier to handle.

    So I changed it to me siteRoot and put in my alias (Make). Do you know what I am doing wrong? My code is below. Please remember I am on 4.0.2.1.

    Thanks again!

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary"
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]"/>

    <xsl:template match="/">

    <!-- start writing XSLT -->

            <!-- Any Ford at or below $currentPage (substitute $siteRoot for $currentPage to grab all Fords in entire site) -->
            <xsl:apply-templates select="$siteRoot/descendant-or-self::*[@isDoc][Make='Ford']"/>
    </xsl:template>

    <!-- Template for any Document Type -->
    <xsl:template match="*[@isDoc]">

    <xsl:value-of select="data [@alias = 'Make']"/>

    <ul><li><h3><a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/></a></h3></li></ul>

    test

    </xsl:template>

    </xsl:stylesheet>

  • Chriztian Steinmeier 2737 posts 8401 karma points MVP 5x admin c-trib
    Dec 05, 2011 @ 08:57
    Chriztian Steinmeier
    0

    Hi again,

    Ah yes, of course - it's for the "legacy XML Schema" - you'll need to change a couple of things:

    First change the way you grab $siteRoot (small change, but in a large site it will make a difference to take only <node> elements instead of 'any'):

    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::node[@level = 1]" />

    then, the apply-templates instruction:

    <xsl:apply-templates select="$siteRoot/descendant-or-self::node[data[@alias = 'Make'] = 'Ford']" />

    - and then the template itself:

    <xsl:template match="node">

    - that's it - should be good to go!

    /Chriztian

  • singer777 69 posts 80 karma points
    Dec 05, 2011 @ 23:13
    singer777
    0

    Thanks so much.

    If it's not too much trouble, I have one follow-up question:

    How would you change this if you wanted it to be Make = Same as the current page's Make. In other words, I would make a category page with the same property and put "Ford" in it. That way, I can do one Macro and have it work for all categories.

    Then, what if I also wanted to make it have to be "Mustang" for the Model.

    So in essense:

    Show all pages in the entire site that match model and make properties of the category page.

    Thank you!

  • Chriztian Steinmeier 2737 posts 8401 karma points MVP 5x admin c-trib
    Dec 06, 2011 @ 08:21
    Chriztian Steinmeier
    0

    Hi,

    You do this by adding or augmenting the "predicate(s)" (an expression in square brackets) - so to match the currentPage's Make, instead of supplying a value, you select that ono on the other side of the equals sign:

    <xsl:apply-templates select="$siteRoot/descendant-or-self::node[data[@alias = 'Make'] = $currentPage/data[@alias = 'Make']]" />

    To also match the Model, you add another predicate, so the complete selection goes like this:

    <xsl:apply-templates select="$siteRoot/descendant-or-self::node
        [data[@alias = 'Make'] = $currentPage/data[@alias = 'Make']]
        [data[@alias = 'Model'] = $currentPage/data[@alias = 'Model']]" />
    
    Hope that gets you going,

    /Chriztian

  • Chriztian Steinmeier 2737 posts 8401 karma points MVP 5x admin c-trib
    Dec 06, 2011 @ 08:25
    Chriztian Steinmeier
    0

    Oh - and it goes without saying that working with the new Schema would make this much more readable, i.e.:

    <xsl:apply-templates select="$siteRoot/descendant-or-self::*[@isDoc][Make = $currentPage/Make][Model = $currentPage/Model]" />

    - Just an appetizer, so you know what a newer version of Umbraco wil do for you :-)

    /Chriztian

  • singer777 69 posts 80 karma points
    Dec 09, 2011 @ 16:57
    singer777
    0

    Thanks again, Chriztian. I am trying it all now!

  • singer777 69 posts 80 karma points
    Dec 15, 2011 @ 23:11
    singer777
    0

    Chriztian,

    This worked wonderfully. Thank you. I ended up matching it to a NODE ID so that the current page doesn't have to have the same properties.

  • singer777 69 posts 80 karma points
    Dec 15, 2011 @ 23:11
    singer777
    0

    Chriztian,

    This worked wonderfully. Thank you. I ended up matching it to a NODE ID so that the current page doesn't have to have the same properties.

Please Sign in or register to post replies

Write your reply to:

Draft