Copied to clipboard

Flag this post as spam?

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


  • Matias 27 posts 68 karma points
    Mar 04, 2013 @ 15:00
    Matias
    0

    Take properties from childs

    Hallo everyone

    I think this is an easy question, but now I have used quite a lot of this day to get it to work, and just wont work. My content area looks like this:

    • Homepage
    • News-overview
    • News 1
    • News 2
    • Ect.
    The thing is that you click on "News-overview", and then it is suppose to retrieve the last 5 news. Inside each news section there are 5 properties:
    • Picture
    • Date
    • Title
    • Text
    • Link
    My problem is that I can't seem to retrieve those properties and put them into the news-overview template.
    My xslt looks like this:
    <xsl:param name="currentPage"/>
    
    <xsl:template match="/">
    
        <xsl:variable name="News" select="$currentPage/@id"/>
        <xsl:for-each select="umbraco.library:GetXmlNodeById($News)/News [@isDoc]">
            <!-- for at den skal kører 5 gange -->
          <xsl:if test="position() &lt;= 5">
              <xsl:variable name="NewsID" select="$currentPage/News/@id"/>    
              <p> <xsl:value-of select="$NewsID" /> </p>
              <!--xsl:variable name="aliasContent" select="umbraco.library:GetItem(NewsID, 'newstitle')"/>
              <p> <xsl:value-of select="$aliasContent" /> </p-->
            <xsl:variable name="propertyAlias" select="string('newslink')"/>
                <li>
                    <div class="news_column1">
                        <img> 
                            <xsl:attribute name="src"> 
                                <xsl:value-of select="newspicture" /> 
                            </xsl:attribute> 
                        </img>
                    </div>
                    <div class="news_column2">
                        <p class="p_news"><xsl:value-of select="newsdate" /></p>
                    </div>
                    <div class="news_column3">
                        <p class="p_bold"><xsl:value-of select="newstitle" /></p>
                        <p><xsl:value-of select="newsnormaltText"/></p>
                        <a>
                            <xsl:for-each select="$currentPage/* [name() = $propertyAlias and not(@isDoc)]/links/link">
                                <xsl:element name="a">
                                <xsl:if test="./@newwindow = '1'">
                                    <xsl:attribute name="target">_blank</xsl:attribute>
                                </xsl:if>
                                <xsl:choose>
                                    <xsl:when test="./@type = 'external'">
                                        <xsl:attribute name="href">
                                            <xsl:value-of select="./@link"/>
                                        </xsl:attribute>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:attribute name="href">
                                            <xsl:value-of select="umbraco.library:NiceUrl(./@link)"/>
                                        </xsl:attribute>
                                    </xsl:otherwise>
                                </xsl:choose>
                                <xsl:value-of select="./@title"/>
                                </xsl:element>
                            </xsl:for-each>                               
                                </a>
                    </div>
                </li>
          </xsl:if>
        </xsl:for-each>
    </xsl:template>
    
    </xsl:stylesheet>

    Any idea how to solve this problem?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 04, 2013 @ 15:08
    Dennis Aaen
    0

    Hi Matias,

    I will try to help you.

    I think you are almost there, from the top of my mind I just think you are missing ./ when you are call those properties.

    So the newsdate should be called like this.

    <div class="news_column2">
        <p class="p_news"><xsl:value-of select="./newsdate" /></p>
    </div>

    Intead of this one, if I rember right.

    <div class="news_column2">
        <p class="p_news"><xsl:value-of select="newsdate" /></p>
    </div>

    I hope this can help you futher.

    /Dennis

  • Matias 27 posts 68 karma points
    Mar 04, 2013 @ 15:24
    Matias
    0

    Hey Dennis

    Thanks for you help, unfortently it did not do anything different. Nothing still shows up.

    I am not sure if the mistake is placed in the way of calling each property, or if it more in the way that the for-each is pointing towards each news.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 04, 2013 @ 15:47
    Dennis Aaen
    0

    Hi Matias,

    I think you could be right.I think your xslt file looks a little advanced out, in relation to your structure.
    If I understand it correctly so live your news items on the news overview.

    With this code you should be able to the the node name out of all the news item. It takes the subpage below the currentpage. so if you put the macro on the news-overview you should get the unordered list a link to the news item and the node name.

    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="$currentPage/News [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:for-each>
    </ul>
    </xsl:template>

    I will try to help you as much as I can.

    /Dennis

  • Matias 27 posts 68 karma points
    Mar 04, 2013 @ 16:00
    Matias
    0

    I made a new xslt from scrath and put your code in there, and that seems to work. It can find all 3 news. So I though it would help to put the for-each in the other xslt, but that did not help anything. So something is still wrong with my calling of the properties. Any idea how to call them then?

     

    This last part is for making a link work, and I am not sure if actually works.

    <a>
                                                   
    <xsl:for-eachselect="$currentPage/* [name() = $propertyAlias and not(@isDoc)]/links/link">
                                                           
    <xsl:elementname="a">
                                                           
    <xsl:iftest="./@newwindow = '1'">
                                                                   
    <xsl:attributename="target">_blank</xsl:attribute>
                                                           
    </xsl:if>
                                                           
    <xsl:choose>
                                                                   
    <xsl:whentest="./@type = 'external'">
                                                                           
    <xsl:attributename="href">
                                                                                   
    <xsl:value-ofselect="./@link"/>
                                                                           
    </xsl:attribute>
                                                                   
    </xsl:when>
                                                                   
    <xsl:otherwise>
                                                                           
    <xsl:attributename="href">
                                                                                   
    <xsl:value-ofselect="umbraco.library:NiceUrl(./@link)"/>
                                                                           
    </xsl:attribute>
                                                                   
    </xsl:otherwise>
                                                           
    </xsl:choose>
                                                           
    <xsl:value-ofselect="./@title"/>
                                                           
    </xsl:element>
                                                   
    </xsl:for-each>                                                        
                                                           
    </a>
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 04, 2013 @ 19:03
    Dennis Aaen
    0

    Hi Matias,

    Is it possible that you can take a screenshot of news document type, so I can see which properties you have attached to it, and what those properties alias.

    I think this will make it easier to help you with a code that works.

    I took a screenshot of the test site so you are on what I mean.

    In my case the document type is SubPage. But on this document type I have these properties.

    /Dennis

  • Matias 27 posts 68 karma points
    Mar 06, 2013 @ 08:55
    Matias
    0

    This is how it looks right now, I might change it for better overview later on. But that should be easy to change in the code. Is that enough info, or do you need more to help me?

     

     

     

  • Matias 27 posts 68 karma points
    Mar 06, 2013 @ 17:12
    Matias
    0

    Most of my problem I solved, but I still have a problem with getting links to work. It's just a general problem with all my xslt files, so I think opens a new subjects.

    Thanks a lot for your help!

Please Sign in or register to post replies

Write your reply to:

Draft