Copied to clipboard

Flag this post as spam?

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


  • Daniel 20 posts 40 karma points
    Aug 03, 2011 @ 23:13
    Daniel
    0

    get data from parent related links

    I've made a structure to control several items on the page as a global element. I now want a related links object on that page to display across the entire site. The issue is, I think, that the "Indstillinger" page is a direct redirect to the "Forside" page below it. ( See here for a screenshot of the structure )

    I've made the entire thing with the basic built-in code and macros - which works when I visualize it, but not in the template. So how do I modify the xslt to pull the data in the template?

    <?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 related links property alias here -->
        
        <!-- selectMenu, is the alias of the Related Links property -->
      <xsl:variable name="propertyAlias" select="string('selectMenu')"/>
      
      <xsl:template match="/">

        <!-- The fun starts here -->
        <ul>
          <xsl:for-each select="$currentPage/* [name() = $propertyAlias and not(@isDoc)]/links/link">
            <li>
              <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>
            </li>
          </xsl:for-each>
        </ul>

        <!-- Live Editing support for related links. -->
        <xsl:value-of select="umbraco.library:Item($currentPage/@id,$propertyAlias,'')" />

      </xsl:template>

    </xsl:stylesheet>

    Sorry if this seems like a totally stupid and silly question.. :S

  • Tom Madden 252 posts 454 karma points MVP 4x c-trib
    Aug 03, 2011 @ 23:57
    Tom Madden
    0

    There's no such thing as a silly question.

    The issue is that your for-each selector is selecting the related links from the current page. Depending on your exact requirement (I'm reading your description in 2 possible ways), you can do one of the following:

    To select from the parent document of the current page, change your for-each to this:

    <xsl:for-eachselect="$currentPage/../* [name() = $propertyAlias and not(@isDoc)]/links/link">

    All I've done here is add ../ to select the data from the parent node

    If you want to use a global setting for every page in your site use this:

    <xsl:for-eachselect="umbraco.library:GetXmlNodeById(1065)/* [name() = $propertyAlias and not(@isDoc)]/links/link">

    In this case, you should changed the 1065 to be the id of the page you want to retreive the data from. You can get this id by hovering the mouse over the node in the content tree and reading the id from the status bar of the browser.

    HTH
    Tom

  • Daniel 20 posts 40 karma points
    Aug 04, 2011 @ 00:01
    Daniel
    0

    Thank you for your help Tom, it's greatly appreciated!

  • MrFlo 159 posts 403 karma points
    Aug 28, 2013 @ 18:01
    MrFlo
    0

    Or to use the home ralated link content, you can use this:

    <xsl:for-each select="$currentPage/ancestor-or-self::*/* [name() = $propertyAlias and not(@isDoc)]/links/link">

    So you don't have to use a number, easier for multiple language structure.

     

     

Please Sign in or register to post replies

Write your reply to:

Draft