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
    Jul 27, 2011 @ 12:42
    Daniel
    0

    if id is same as contentpicker value

    Having some issues with assigning a 'current' class to a macro. Basically I've created a custom menu from four content pickers which is pointing to specific sections of the site - however I cannot figure out how to create an 'active state' to the menu points.

    <?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"/>
        
    <xsl:variable name="level" select="2"/>


    <xsl:template match="/">

    <!-- start writing XSLT -->

      <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]">
      <ul id="priorityMenu">
        <li>
          <a href="{umbraco.library:NiceUrl(firstLink)}" class="speech">
            <xsl:value-of select="firstLinkName"/>
          </a>
        </li>
        <li>
          <a href="{umbraco.library:NiceUrl(secondLink)}" class="speech">
            <xsl:value-of select="secondLinkName"/>
          </a>
        </li>
        <li>
          <a href="{umbraco.library:NiceUrl(thirdLink)}" class="speech">
            <xsl:value-of select="thirdLinkName"/>
          </a>
        </li>
        <li>
          <a href="{umbraco.library:NiceUrl(fourthLink)}" class="speech">
            <xsl:value-of select="fourthLinkName"/>
          </a>      
        </li>
      </ul>  
      </xsl:for-each>
      
    </xsl:template>

    </
    xsl:stylesheet>

    So now I need to figure out if the current page that I am on is the same as one the four individual links, and if so - attach the 'current' class to each of them.

    Does it make sense? I'm not much of a guru yet to this but at least I'm learning! :)

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 27, 2011 @ 12:58
    Jeavon Leopold
    1

    Hi Daniel,

    Try this:

    <?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"/>
    
    <xsl:variable name="level" select="2"/>
    
    
    <xsl:template match="/">
    
    <!-- start writing XSLT -->
    
      <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]">
      <ul id="priorityMenu">
        <li>
          <a href="{umbraco.library:NiceUrl(firstLink)}" class="speech">
           <xsl:if test="$currentPage/@id = firstLink">
            <xsl:attribute name="class">selected speech</xsl:attribute>
           </xsl:if>
            <xsl:value-of select="firstLinkName"/>
          </a>
        </li>
        <li>
          <a href="{umbraco.library:NiceUrl(secondLink)}" class="speech">
           <xsl:if test="$currentPage/@id = secondLink">
            <xsl:attribute name="class">selected speech</xsl:attribute>
           </xsl:if>    
            <xsl:value-of select="secondLinkName"/>
          </a>
        </li>
        <li>
          <a href="{umbraco.library:NiceUrl(thirdLink)}" class="speech">
           <xsl:if test="$currentPage/@id = thirdLink">
            <xsl:attribute name="class">selected speech</xsl:attribute>
           </xsl:if>        
            <xsl:value-of select="thirdLinkName"/>
          </a>
        </li>
        <li>
          <a href="{umbraco.library:NiceUrl(fourthLink)}" class="speech">
           <xsl:if test="$currentPage/@id = fourthLink">
            <xsl:attribute name="class">selected speech</xsl:attribute>
           </xsl:if>        
            <xsl:value-of select="fourthLinkName"/>
          </a>      
        </li>
      </ul>  
      </xsl:for-each>
    
    </xsl:template>
    </xsl:stylesheet>
    
  • Daniel 20 posts 40 karma points
    Jul 27, 2011 @ 13:02
    Daniel
    0

    Thank you! Much appreciated, that did the trick!

    I figured it wasn't that difficult and I'm sure I could've figured it out myself - must've hit a wall there. :D

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 27, 2011 @ 13:24
    Jeavon Leopold
    0

    You're welcome! And welcome to the Umbraco community!

Please Sign in or register to post replies

Write your reply to:

Draft