Copied to clipboard

Flag this post as spam?

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


  • Rik Helsen 670 posts 873 karma points
    Jul 27, 2010 @ 10:00
    Rik Helsen
    0

    xslt: how to check if any child from a set source has children with a certain propertyvalue ?

    Another more challenging xslt question for me, i'm trying to relate jobs to country pages (under Network)

    I need to list all children of "jobs" on the country pages (under network), if their "relatedCountry" matches $currentpage/id

    I was thinking along these lines, but got stuck:

     

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

    <!-- 'source' of the children to list -->

    <xsl:variable name="source" select="/macro/source"/>

    <xsl:template match="/">

    <xsl:choose>

    <!-- Here i need to test if the children of $source/children/@ultimatepickerid match $currentpage/@id-->

    <xsl:when test="count(umbraco.library:GetXmlNodeById($source)/* [@isDoc]) &gt; 0">   
    <ul>
    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:for-each>
    </ul>
    </xsl:when>
    <xsl:otherwise>
        <li>
          <li>
            There are currently no job openings in <xsl:value-of select="relatedCountry"/>. <a href="/en/jobs">Browse all jobs</a>.
      </li>
      </li>
    </xsl:otherwise>
    </xsl:choose>  
      
    </xsl:template>
    </xsl:stylesheet>

    Can anyone give an example of how to match this? I need to do it in the choose statement because i want to eliminate the empty UL element if there are no matches, and give alternative out ("there are currently no jobs...")

     

     

  • Rik Helsen 670 posts 873 karma points
    Jul 27, 2010 @ 10:10
    Rik Helsen
    0

    maybe something along these lines should return a count of children with matching property relatedcountry?

    <xsl:value-of select="count(umbraco.library:GetXmlNodeById($source)/* [@isDoc and @relatedCountry = '0'])"/>

  • Rik Helsen 670 posts 873 karma points
    Jul 27, 2010 @ 10:19
    Rik Helsen
    0

    Found this solution:

    <?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">Related Jobs</a>
    <xsl:choose>
    <xsl:when test="count(umbraco.library:GetXmlNodeById($source)/*
    [@isDoc and relatedCountry = $currentPage/@id]) &gt; 0 and
    string(umbracoNaviHide) != '1'"
    >    
    <ul>
    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and relatedCountry = $currentPage/@id and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:for-each>
    </ul>
    </xsl:when>
    <xsl:otherwise>
          
      There are currently no job openings in <xsl:value-of select="$currentPage/@nodeName"/>. <a href="/en/jobs">Browse all jobs</a>.

    </xsl:otherwise>
    </xsl:choose>  
      
    </xsl:template>
    </xsl:stylesheet>

    Thanks to this topic: http://our.umbraco.org/forum/developers/xslt/9587-Count-number-of-posts-with-category-selected

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies