Copied to clipboard

Flag this post as spam?

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


  • Nicky Christensen 19 posts 40 karma points
    Dec 04, 2009 @ 14:39
    Nicky Christensen
    0

    Whats wrong with my for each?

    Im  listing a number of products on my page - I've created a xslt and macro for this - But cant get it to output anything in the for each loop? If i type in something outside the foreach loop it renders?

    the Alias that is in the document type i want is "ProdCat"

    Here's the xslt:

    <?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"
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

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

    <xsl:param name="currentPage"/>

    <!-- Input the documenttype you want here -->
    <xsl:variable name="documentTypeAlias" select="string('weblogItem')"/>

    <xsl:template match="/">
    <xsl:value-of select="@nodeTypeAlias" disable-output-escaping="yes"/>
    <!-- The fun starts here -->
    <xsl:for-each select="$currentPage/node [@nodeTypeAlias = 'ProdCat' and string(data [@alias='umbracoNaviHide']) != '1']">
        <div class="prodcatbox">
            <h2><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="data [@alias = 'ProdCatName']"/></a></h2>
            <div class="boxtop"><!----></div>
            <div class="boxmiddle">
                <xsl:if test="$currentPage/data [@alias='Media'] != ''">
                    <div class="catimage">
                        <img alt="{$currentPage/@nodeName}" title="{$currentPage/@nodeName}" class="cat_image">
                                      <xsl:attribute name="src">
                                <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias='Media'], 'false')/data [@alias = 'umbracoFile']" />
                                      </xsl:attribute>   
                                </img>
                    </div>
                </xsl:if>
                <div class="catsummary">
                    <xsl:value-of select="data[@alias = 'ProdCatShortDesc']"/>
                </div>
            </div>
            <div class="boxbottom"><!----></div>
        </div>
    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>

  • Doogie Talons 183 posts 318 karma points
    Dec 04, 2009 @ 15:01
    Doogie Talons
    0

    I believe you don't need the and

     

    [@nodeTypeAlias = 'ProdCat' and string(data [@alias='umbracoNaviHide']) != '1']

     

    becomes

     

    [@nodeTypeAlias = 'ProdCat' ] [string(data [@alias='umbracoNaviHide']) != '1']

  • Doogie Talons 183 posts 318 karma points
    Dec 04, 2009 @ 15:08
    Doogie Talons
    0

    Also the current page calls... am I correct in thinking they are to render data within the iteration ?for example if $currentPage/@nodeName is supposed to be one of the ProdCat nodes then you would just use

    @nodeName

     

    ignore the AND post both will work.

     

     

  • Nicky Christensen 19 posts 40 karma points
    Dec 07, 2009 @ 10:00
    Nicky Christensen
    0

    Hmm, still cant get it to work.....

    What i want is to display my Product Categories on my frontpage - So i created an xslt file, of the type: List Subpages by Document Type.

    The Document Type alias is: "ProdCat" - But i cant get it to display anything at all??

    My "sitetree" looks like:

    Frontpage
    About
    News
    Produkt
       - Productcategory1
          -  Product1
       - Productcategory2

    My xslt is now:

     

    <?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"
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

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

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <xsl:for-each select="$currentPage/node [@nodeTypeAlias = 'ProdCat']">
        <div class="prodcatbox">
            <h2><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="data [@alias = 'ProdCatName']"/></a></h2>
            <div class="boxtop"><!----></div>
            <div class="boxmiddle">
                <xsl:if test="$currentPage/data [@alias='Media'] != ''">
                    <div class="catimage">
                        <img alt="{$currentPage/@nodeName}" title="{$currentPage/@nodeName}" class="cat_image">
                                      <xsl:attribute name="src">
                                <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias='Media'], 'false')/data [@alias = 'umbracoFile']" />
                                      </xsl:attribute>  
                                </img>
                    </div>
                </xsl:if>
                <div class="catsummary">
                    <xsl:value-of select="data[@alias = 'ProdCatShortDesc']"/>
                </div>
            </div>
            <div class="boxbottom"><!----></div>
        </div>
    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>

     

  • Tommy Poulsen 514 posts 708 karma points
    Dec 07, 2009 @ 10:23
    Tommy Poulsen
    0

    Hi Nicky, for what node in your sitetree have you added the macro-call (directly or using a template)?

  • Nicky Christensen 19 posts 40 karma points
    Dec 07, 2009 @ 10:24
    Nicky Christensen
    0

    It's in my template "Master" like this:

    <%@ Master Language="C#" MasterPageFile="/umbraco/masterpages/default.master" AutoEventWireup="true" %>
    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"[]>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head id="head" runat="server">
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
            <title><asp:placeholder runat="server"><umbraco:Item runat="server" field="pageName" /> - <umbraco:Item runat="server" field="siteName" recursive="true" /></asp:placeholder></title>
            <link rel="stylesheet" type="text/css" href="/css/markings.css" />
    </head>
        <body>
        <div id="container">
            <div class="wrapper">
                <div id="top">
                    <div class="servicemenu">
                        <img src="/images/addfavorite.gif" alt="Tilføj som favorit" title="Tilføj som favorit" />
                        <img src="/images/print.gif" alt="Print siden" title="Print siden" />
                        <img src="/images/rss.gif" alt="RSS" title="RSS" />
                    </div>
                </div>
                <div id="header">
                    <div class="logo">
                        <a href="/" title="Markings"><img src="/images/blank.png" width="130" height="95" alt="Markings" title="Markings" /></a>
                    </div>
                    <div class="headerelements">
                        Punchlines
                    </div>
                </div>
                <div id="menubar">
                    <div id="menu">
                        <umbraco:Macro Alias="RunwayTopNavigation" runat="server" />
                    </div>
                    <div id="search">
                        Søgning her
                    </div>
                    <div class="reset"><!----></div>
                </div>
                <div id="maincontent">
                    <div class="maincnttop"><!----></div>
                    <div class="content">
                        <form id="RunwayMasterForm" runat="server">
                            <asp:ContentPlaceHolder ID="RunwayMasterContentPlaceHolder" runat="server"></asp:ContentPlaceHolder>

                        </form>
                       
                       
                        <umbraco:Macro Alias="ProdCats" runat="server"></umbraco:Macro>

                       
                    </div>
                    </div>
                </div>
                <div id="footer">
                   
                </div>
            </div>
        </div>               
        </body>
    </html>
    </asp:content>

  • Tommy Poulsen 514 posts 708 karma points
    Dec 07, 2009 @ 10:34
    Tommy Poulsen
    0

    By using a reference like this:

    <xsl:for-each select="$currentPage/node [@nodeTypeAlias = 'ProdCat']">

    you only refer to your immediate children (and not descendants).

    You could add a cointent-picker argument/property to your macro to identify the "Produkt" node, and then refer to child nodes of this selected node. Otherwise (if you always know the position of the "Produkt"-node) you can refer to it absolutely using e.g. the root node of the content tree (you can get this using the library function GetXmlAll())

    >Tommy

  • Tommy Poulsen 514 posts 708 karma points
    Dec 07, 2009 @ 10:37
    Tommy Poulsen
    0

    For easy testing you script you can try:

    <xsl:for-each select="$currentPage/descendant::node [@nodeTypeAlias = 'ProdCat']">

    but this would be be a nice "real" solution as you would be searching all descendants of the current page - not only the Produkt page

  • Nicky Christensen 19 posts 40 karma points
    Dec 07, 2009 @ 10:50
    Nicky Christensen
    0

    But even if i replace my for-each with:

    <xsl:for-each select="$currentPage/descendant::node [@nodeTypeAlias = 'ProdCat']">

    It still wont output anything? :( 

    Im not sure of what you mean by adding a content picker, and identify the Produkt node? It's my first site in Umbraco so im not that exp with the system... I've watched all of the videos that they have in umbraco, but there's nothing that relates to this problem :(

  • Tommy Poulsen 514 posts 708 karma points
    Dec 07, 2009 @ 10:52
    Tommy Poulsen
    0

    what node is your $currenPage referring to?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 07, 2009 @ 10:53
    Dirk De Grave
    0

    If it's in your master template, you probably want the product categories to appear on all pages, no matter where you are in the structure. Tommy's solution is quite close, you could also:

    <xsl:for-each select="umbraco.library:GetXmlAll()/descendant::node [@nodeTypeAlias = 'ProdCat']">

    which will work from any page, regardless of the level or current page you're browsing.

     

    Cheers,

    /Dirk

  • Tommy Poulsen 514 posts 708 karma points
    Dec 07, 2009 @ 11:05
    Tommy Poulsen
    0

    To add a content picker proprty, go to your Macro definition in the Developer section.

    In the right pane, click on the "Parameters" tab. Here you can enter name and alias for you new parameter, and then select "contentPicker" in the drop down.

    When adding a macro to a template you will be prompted to select a node in the content tree - in your case select the Produkt-node.

    In your xslt you create a variable selecting the paramter value, and use that as your reference for the Produkt-node. Something like this:

    <xsl:variable name="MyNode" select="/macro/yourParameterAlias"/>

    See more about macros here:http://umbraco.org/documentation/books/macro-parameters-syntax/an-overview-of-all-the-macro-parameters

  • Nicky Christensen 19 posts 40 karma points
    Dec 07, 2009 @ 11:34
    Nicky Christensen
    0

    Hmm, guess $currentPage is referring to itself (The page im at, Frontpage)? - Could this be the problem, because the Product Categories is created on another page, under the page "Products"!

  • Tommy Poulsen 514 posts 708 karma points
    Dec 07, 2009 @ 11:41
    Tommy Poulsen
    0

    This is exactly why you do not get any nodes when doing a search on immediate children of the currentpage.

    Instead, use the getxmlall() funtion as your base-reference instead of $currentpage as Dirk suggests, or add a macro property as described above.

Please Sign in or register to post replies

Write your reply to:

Draft