Copied to clipboard

Flag this post as spam?

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


  • curlybub 133 posts 107 karma points
    Jul 21, 2010 @ 11:29
    curlybub
    0

    XSLT and tables

    Hi Umbraco People,

    Im trying to achieve the image below using XSLT.

     

    I tried creating my own XSLT, I'm having a problem placing the TR and with the condition to use. Here is the output of my XSLT.

    I can make the name an outher information appear but not the image. What I want to happen is to create a TR for the first item and the 2nd should be on a TD, the third and fourt item should be on a seperate TR and TD.
    Below is the XSLT that I created.

    <?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:variable name="currentID" select="$currentPage/@id"/>
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <xsl:variable name="modelThumbnail" select="/macro/modelThumbnail"/>
    <xsl:for-each select="$currentPage/node[@nodeTypeAlias = 'freewayCarModelCategory']">
     <div id="modelListArea">
          <div id="modelList">
               <table border="0" cellpadding="0" cellspacing="0">
       <tbody>
            <tr>
                                 <td class="tableHeader"><h2><xsl:value-of select="@nodeName"/></h2></td>
            </tr>
                       </tbody>
                       </table>
                       <table border="0" cellpadding="0" cellspacing="0">
       <tbody>
            <tr>  
            <xsl:for-each select="node[@nodeTypeAlias = 'freewayCarModelItem']">
            <xsl:variable name="pos" select="position() mod 3" />
            <xsl:choose>
       <xsl:when test="$pos = 0"> 
        <td class="modelImageArea modelImage">
        <xsl:variable name="mediaId" select="number($currentPage/data[@alias='modelThumbnail'])" />
        <xsl:if test="$mediaId &gt; 0">
         <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
         <xsl:if test="count($mediaNode/data) &gt; 0 and string($mediaNode/data[@alias='umbracoFile']) != ''">
          <img src="{$mediaNode/data[@alias='umbracoFile']}" alt="[image]" height="{$mediaNode/data[@alias='umbracoHeight']}" width="{$mediaNode/data[@alias='umbracoWidth']}" />
         </xsl:if>
        </xsl:if>
          </td>
          <td class="modelDescription">
                <div><span class="modelName"><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></span><br/>
                             <xsl:value-of select="data [@alias = 'modelDescription']" disable-output-escaping="yes" /><br/>
             <xsl:value-of select="data [@alias = 'modelPrice']" disable-output-escaping="yes" />
                </div>
          </td>
       </xsl:when>
       <xsl:otherwise>
        <tr>
        <xsl:if test="$pos != 0">   
        <td class="modelImageArea modelImage">
        <xsl:variable name="mediaId" select="number($currentPage/data[@alias='modelThumbnail'])" />
        <xsl:if test="$mediaId &gt; 0">
         <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
         <xsl:if test="count($mediaNode/data) &gt; 0 and string($mediaNode/data[@alias='umbracoFile']) != ''">
          <img src="{$mediaNode/data[@alias='umbracoFile']}" alt="[image]" height="{$mediaNode/data[@alias='umbracoHeight']}" width="{$mediaNode/data[@alias='umbracoWidth']}" />
         </xsl:if>
        </xsl:if>
          </td>
          <td class="modelDescription">
                <div><span class="modelName"><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></span><br/>
                             <xsl:value-of select="data [@alias = 'modelDescription']" disable-output-escaping="yes" /><br/>
             <xsl:value-of select="data [@alias = 'modelPrice']" disable-output-escaping="yes" />
                </div>
          </td>
         </xsl:if>
        </tr>
       </xsl:otherwise>
            </xsl:choose>
            </xsl:for-each>
            </tr>
                     
       </tbody>
       </table>                
                   </div>
              </div>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>


    The structure of my content is
    MODEL Line Up
    ---------Cars
              -------Car1
              -------Car2
              -------Car3
    ---------SUV
              -------SUV1
              -------SUV2
              -------SUV3

    Maybe you can help me make the thumbnails appear too. Hehe. Im pretty sure im using the correct code to display the images that the media picker picked. However it is not working.

    More power to you guys.

    Thank you.

    Regards,
    Harry

  • curlybub 133 posts 107 karma points
    Jul 22, 2010 @ 04:55
    curlybub
    0

    Anyone? :D

    -Homepage
    ---------MODEL Line Up (the xslt macro is here to get the categories and cars)
              ---------Cars
                          -------Car1 (thumbnail, price and small description is here)
                          -------Car2
                          -------Car3
              ---------SUV
                          -------SUV1
                          -------SUV2
                          -------SUV3

  • Folkert 82 posts 212 karma points
    Jul 22, 2010 @ 09:55
    Folkert
    1

    I think you're trying to receive the image with:

      name="mediaId" select="number($currentPage/data[@alias='modelThumbnail'])" />

    That's a request for the image from the currentpage. You're inside a nested loop so, the image is coming from a Car, so you should use something like:

      name="mediaId" select="number(data[@alias='modelThumbnail'])" />
  • Folkert 82 posts 212 karma points
    Jul 22, 2010 @ 10:02
    Folkert
    0

    Personally, I don't like tables, just use it for tabular data. In this case i would use other markup like:

    <xsl:foreach select="all categories">
        <h2>Cars</h2>
        <div class="category">
            <xsl:foreach select="all cars">
                <div class="car">
                    <img src="#" alt="name"/>
                    <ul>
                        <li><a href="#">name of the car</a></li>
                        <li>property 1</li>
                        <li>property 2</li>
                    </ul>
                </div>   
            </xsl:foreach>
        </div>
    </xsl:foreach>

    Use css for styling.

  • curlybub 133 posts 107 karma points
    Jul 22, 2010 @ 10:59
    curlybub
    0

    Hi Folkert

    Thanks for the tip. The markup that you posted will render the same output with what I'm getting.

    Image1 Property1
    Image2 Property2
    Image3 Property3
    Image4 Property4

    What I want to achieve is something like:

    Image1 Property1                    Image2 Property2
    Image3 Property3                    Image4 Property4

    How can I make the 2nd node to go to the left of the 1st node and the 3rd node to be on the next line.

    Regards,
    Harry

  • Folkert 82 posts 212 karma points
    Jul 22, 2010 @ 11:08
    Folkert
    3

    Themarkup I posted wil just render the ouput, nothing will happen unless you use css. Choose correct markup for the elements you're using. Using tables is just for tabular data.

    Having a layout, like yours you have to define the xslt like:

    <xsl:foreach select="all categories">
        <div class="category">   
            <h2>Cars</h2>
            <xsl:foreach select="all cars">
                <div class="car">
                    <img src="#" alt="name"/>
                    <ul>
                        <li><a href="#">name of the car</a></li>
                        <li>property 1</li>
                        <li>property 2</li>
                    </ul>
                </div>   
            </xsl:foreach>
            <div class="clear"></div>
        </div>
    </xsl:foreach>
    <div class="clear"></div>

    and some css like:

    div.category h2
    {
        border-bottom:solid 1px #666;
    }

    div.car
    {
        float:left;
        width:300px;
        height:200px;
    }

    div.car img
    {
        float:left;
        margin-right:10px;
    }

    .clear
    {
    clear:both;
    height:0;
    visibility:hidden;
    width:0;
    }

    This is just a small guide/idea and is not tested, for setting up pages with proper css,just use google.

  • curlybub 133 posts 107 karma points
    Jul 23, 2010 @ 08:29
    curlybub
    0

    Hi Folkert,

    I understand what you are trying to say. But this will still not give me the output that I need. What I'm trying to achieve is this.

    Upon looking on the mark-up and css that you posted, it will render the layout for each node. But it will not achieve the layout above, it will still display all the nodes vertically. Some conditioning statement must be placed on the xslt, but that is where im having a problem.

    Thank you.

    Regards,
    Harry

  • Folkert 82 posts 212 karma points
    Jul 23, 2010 @ 09:53
    Folkert
    0

    If you use float, block elements will not render vertically but horizontally. Search for google in using floats:
    for example:
    http://www.elated.com/articles/css-floats/

    Example of float:

    <div style="float: left; width: 200px; margin-right: 5px;">
    <p>
    This is our left text column.
    This is our left text column.
    This is our left text column.
    </p>
    </div>

    <div style="float: left; width: 200px; margin-right: 5px;">
    <p>
    This is our right text column.
    This is our right text column.
    This is our right text column.
    This is our right text column.
    This is our right text column.
    </p>
    </div>

    <div style="clear: both;"> </div>
  • curlybub 133 posts 107 karma points
    Jul 23, 2010 @ 10:29
    curlybub
    0

    I think we are not on the same page here. I understand how to use floats and block elements.

    Let me explain again. I have this kind of structure:

    Homepage
      Model Line Up
           Cars
               Car1
               Car2
               Car3
               Car4
           SUV
               SUV1
               SUV2
               SUV3
               SUV4

    My xslt is on the Model Line Up node, what the xslt does is to display the category and the items under it. So I have a looping statement for the categories and nested in it is another looping statement for the items under it.

    What I'm having problems with is iterating through the items under each category. My current xslt outputs something like this:

    Cars
      Car1
      Car2
      Car3
      Car4

    SUV
      Suv1
      Suv2
      Suv3
      Suv4

    What I'm trying to achieve is:
    Cars
      Car1      Car2
      Car3      Car4

    SUV
      Suv1      Suv2
      Suv3      Suv4

    My question is how can I limit the display to 2 items horizontally, when it reaches the 3rd item it displays the next 2 items on the next line. I tried to control it by using the pos() function, but I guess im missing something important.

    Thank you.

    Regards,
    Harry 

     

  • Folkert 82 posts 212 karma points
    Jul 23, 2010 @ 10:58
    Folkert
    1

    Justmake the floats half the size of the container. a float will be placed left to the previous element. If there is no space anymore, the float will be on the next 'line'. Make sure you're clearing the floats after each list of cars, so before every category, otherwise, the categories will be rendered in the wrong flow.

    You don't have to use position().

  • wolulcmit 357 posts 693 karma points
    Jul 23, 2010 @ 11:00
    wolulcmit
    1

    you can either limit your items to 2 horizontally by either setting your cotaining div with to be only two cars wide.

    using a simplified version of Folkerts example:

    <div class="cars">
    <h3>Cars</h3>
    <div
    class="car">
    <!-- all html for car 1 contained here -->
    </div>

    <div class="car">
    <!-- all html for car 2 contained here -->
    </div>

    <div class="car">
    <!-- all html for car 3 contained here -->
    </div>
    <div class="car">
    <!-- all html for car 4 contained here -->
    </div>

    </div>
    <div class="suvs">
    <h3>SUV</h3>
    <div class="suv">
    <!-- all html for suv 1 contained here -->
    </div>

    <div class="suv">
    <!-- all html for suv 2 contained here -->
    </div>

    <div class="suv">
    <!-- all html for suv 3 contained here -->
    </div>
    <div class="suv">
    <!-- all html for suv 4 contained here -->
    </div>

    </div>

    .car, .suv{width:100px; float:left; display:block;}
    .cars, .suv{clear:left; width:200px}

    you'd probably want to put some margins or padding in there too... but for the purpose of a demo it's fine.
    the above should give you:

    Cars
      Car1      Car2
      Car3      Car4

    SUV
      Suv1      Suv2
      Suv3      Suv4

    that should be it, unless I'm not reading you right?

  • curlybub 133 posts 107 karma points
    Jul 23, 2010 @ 11:08
    curlybub
    0

    Thanks Flokert and wolulcmit!

    That makes sense. I'll try it out.

    Again guys, thank you! I'll post again if it works for me or not.

  • Folkert 82 posts 212 karma points
    Jul 23, 2010 @ 11:13
    Folkert
    1

    Here a sample for you, better worked out, just copy/paste:

     

    <html>
    <head>
        <style>
            .category
            {
                width: 650px;
                background-color:#f5f5f5;
                margin-bottom:10px;           
            }
            .category h2
            {
                border-bottom:solid 3px #e5e5e5;
            }
            .car
            {
                width:300px;
                float:left;
                margin-right:20px;
                margin-bottom:10px;
                border:solid 1px #e5e5e5;
                background-color:#fff;
            }   
            .car ul li
            {
                list-style-type:none;
            }
            .car img
            {
                float:left;
                margin-right:10px;
            }
           
            .clear
            {
                clear:both;
                height:0;
                visibility:hidden;
                width:0;
                display:block;
                overflow:hidden;
            }
           
        </style>
    </head>
    <body>
        <div class="category">   
            <h2>Cars</h2>
            <div class="car">
                <img src="http://farm1.static.flickr.com/120/263634525_dbeb2ef303_m.jpg" alt="name" width="150"/>
                <ul>
                    <li><a href="#">name of the car</a></li>
                    <li>property 1</li>
                    <li>property 2</li>
                </ul></div>
            <div class="car">
                <img src="image.jpg" alt="name" width="150"/>
                <ul>
                    <li><a href="#">name of the car</a></li>
                    <li>property 1</li>
                    <li>property 2</li>
                </ul>
            </div>
            <div class="car">
                <img src="image.jpg" alt="name" width="150"/>
                <ul>
                    <li><a href="#">name of the car</a></li>
                    <li>property 1</li>
                    <li>property 2</li>
                </ul>
            </div>
            <div class="car">
                <img src="image.jpg" alt="name" width="150"/>
                <ul>
                    <li><a href="#">name of the car</a></li>
                    <li>property 1</li>
                    <li>property 2</li>
                </ul>
            </div>
            <div class="car">
                <img src="image.jpg" alt="name" width="150"/>
                <ul>
                    <li><a href="#">name of the car</a></li>
                    <li>property 1</li>
                    <li>property 2</li>
                </ul>
            </div>
            <br class="clear"/>
        </div>
        <div class="category">   
            <h2>Cars</h2>
            <div class="car">
                <img src="image.jpg" alt="name" width="150"/>
                <ul>
                    <li><a href="#">name of the car</a></li>
                    <li>property 1</li>
                    <li>property 2</li>
                </ul></div>
            <div class="car">
                <img src="image.jpg" alt="name" width="150"/>
                <ul>
                    <li><a href="#">name of the car</a></li>
                    <li>property 1</li>
                    <li>property 2</li>
                </ul>
            </div>
            <div class="car">
                <img src="image.jpg" alt="name" width="150"/>
                <ul>
                    <li><a href="#">name of the car</a></li>
                    <li>property 1</li>
                    <li>property 2</li>
                </ul>
            </div>
            <br class="clear"/>
        </div>
        <div class="category">   
            <h2>Cars</h2>
            <div class="car">
                <img src="image.jpg" alt="name" width="150"/>
                <ul>
                    <li><a href="#">name of the car</a></li>
                    <li>property 1</li>
                    <li>property 2</li>
                </ul></div>
            <div class="car">
                <img src="image.jpg" alt="name" width="150"/>
                <ul>
                    <li><a href="#">name of the car</a></li>
                    <li>property 1</li>
                    <li>property 2</li>
                </ul>
            </div>
            <div class="car">
                <img src="image.jpg" alt="name" width="150"/>
                <ul>
                    <li><a href="#">name of the car</a></li>
                    <li>property 1</li>
                    <li>property 2</li>
                </ul>
            </div>
            <br class="clear"/>
        </div>
    </body>

     

Please Sign in or register to post replies

Write your reply to:

Draft