Copied to clipboard

Flag this post as spam?

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


  • Bjørn Fridal 274 posts 784 karma points
    Sep 22, 2010 @ 17:00
    Bjørn Fridal
    0

    Get pages that has a related link to the current page.

    Hi,

    I am hoping someone can help me out with this one. I am trying to find all the pages that has a related links to the my current page. So that's the other opposite way of its normal use.

    I currently have the following code that almost does what I want, but it returns the first match multiple times:

    node [data[@alias='productLists']/links/link[@link=$currentPage/@id]]

     

    I have tried to illustrate what I am after below:

    Cheers
    Bjørn Fridal

  • Rik Helsen 670 posts 873 karma points
    Sep 22, 2010 @ 17:18
    Rik Helsen
    0

    I have it for Umbraco 4.5.x :

    <?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"/>

    <!-- Don't change this, but add a 'contentPicker' element to -->
    <!-- your macro with an alias named 'source' -->
    <xsl:variable name="source" select="/macro/source"/>

    <xsl:template match="/">
     <a href="/en/jobs" class="jobstitle">Jobs in <xsl:value-of select="$currentPage/@nodeName"/></a>
    <xsl:choose>
      <xsl:when test="count(umbraco.library:GetXmlNodeById($source)/* [@isDoc and relatedAirport = $currentPage/@id and string(umbracoNaviHide) != '1']) &gt; 0 ">
        <ul class="jobslist">
          <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and relatedAirport = $currentPage/@id and string(umbracoNaviHide) != '1']">
            <li>
              <a href="{umbraco.library:NiceUrl(@id)}">
              <span class="jobtitle">» <xsl:value-of select="@nodeName"/></span>
              </a>
            </li>
          </xsl:for-each>
        </ul>
      </xsl:when>
      <xsl:otherwise><ul class="jobslist"><li><span class="jobtitle">There are currently no job openings.<br /><br />
        <a href="/en/jobs">» Browse all jobs</a></span></li></ul></xsl:otherwise>
    </xsl:choose>
    </xsl:template>
    </xsl:stylesheet>
  • Bjørn Fridal 274 posts 784 karma points
    Sep 22, 2010 @ 19:01
    Bjørn Fridal
    0

    Hi Rik,

    That looks interesting, but I am not sure I can apply the same technique. At least I can't get it working.

    This is an older Umbraco installation so its using the legacy xml schema.

    Cheers
    Bjørn Frilda

  • Rik Helsen 670 posts 873 karma points
    Sep 28, 2010 @ 09:26
  • Bjørn Fridal 274 posts 784 karma points
    Oct 28, 2010 @ 14:18
    Bjørn Fridal
    0

    Thanks for the effort Rik. The blog post didn't have quite what I was looking for, but eventually I got it working. Instead of storing the returned nodes in a variable I use the XPath query directly in a for-each:

    <xsl:for-each select="node [data[@alias='productLists']/links/link[@link=$currentPage/@id]]">
    <!-- do stuff -->
    </xsl:for-each>
Please Sign in or register to post replies

Write your reply to:

Draft