Copied to clipboard

Flag this post as spam?

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


  • Kevon K. Hayes 255 posts 281 karma points
    Nov 10, 2010 @ 00:18
    Kevon K. Hayes
    0

    Tryin to output the value of custom property if another property is null

    The the "otherwise" block works but not the "when" block.

    <xsl:template match="/">
    <!-- Creating ID of the Menu Container -->
      <xsl:variable name="id" select="$currentPage/corMenuItemsID" />
      <ul>
       <!--- Getting the Menu Items in the Container-->
      <xsl:for-each select="umbraco.library:GetXmlNodeById($id)/corDeptMenuItem [@isDoc]">
        <!-- Setting variable to get the URL from below property -->
        <xsl:variable name="theURL" select="umbraco.library:NiceUrl(corDeptMenuItemLink)" />
        <!-- Setting variable to get the text value from below property -->
        <xsl:variable name="corURLValue" select="umbraco.library:Item($currentPage/@id, 'corURL')" />
        <xsl:choose>
          <!-- if the value of the corDeptMenuItemLink is null or "" output the value of corURL property-->
          <xsl:when test="theURL = ''">
            <li>
              <a href="corURLValue">
                <xsl:value-of select="@nodeName"/>
              </a>
            </li>
          </xsl:when>
          <!-- otherwise output the URL of the value of the URL of the corDeptMenuItemLink property-->
          <xsl:otherwise>
            <li>
              <a href="{umbraco.library:NiceUrl(corDeptMenuItemLink)}">
              <xsl:value-of select="@nodeName"/>
              </a>
            </li>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </ul>
    </xsl:template>

  • Almir Vereget 62 posts 150 karma points
    Nov 10, 2010 @ 09:31
    Almir Vereget
    0

    Hi,

    On quick look i see you are calling your variables (theURL and corURLValue) vithout $ sign.

     <xsl:when test="theURL = ''"> should be  <xsl:when test="$theURL = ''">

    Could that be the problem?

  • Kevon K. Hayes 255 posts 281 karma points
    Nov 10, 2010 @ 15:23
    Kevon K. Hayes
    0

    I made the suggested change.. still no output. 

    This is the node structure

     

    This is the where if the Item Link value hasn't been selected/blank/null then i'd like to choose the value of the URL property.

     

    The code looks lke this so far:

    <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" xmlns:MailEngine="urn:MailEngine"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets MailEngine ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <!-- Creating ID of the Menu Container -->
      <xsl:variable name="id" select="$currentPage/corMenuItemsID" />
      <ul>
       
      <!--- Getting the Menu Items in the Container-->
      <xsl:for-each select="umbraco.library:GetXmlNodeById($id)/corDeptMenuItem [@isDoc]">
        <!-- Setting variable to get the URL from below property -->
        <xsl:variable name="theURL" select="umbraco.library:NiceUrl(corDeptMenuItemLink)" />
        
        <!-- Setting variable to get the text value from below property -->
        <xsl:variable name="corURLValue" select="umbraco.library:Item($currentPage/@id, 'corURL')" />
        
        <xsl:choose>
          <!-- if the value of the corDeptMenuItemLink is null or "" output the value of corURL property-->
          <xsl:when test="$theURL = ''">
            <li>
              <a href="$corURLValue">
                <xsl:value-of select="@nodeName"/>
              </a>
            </li>
          </xsl:when>
          <!-- otherwise output the URL of the value of the URL of the corDeptMenuItemLink property-->
          <xsl:otherwise>
            <li>
              <a href="{umbraco.library:NiceUrl(corDeptMenuItemLink)}">
              <xsl:value-of select="@nodeName"/>
              </a>
            </li>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </ul>
    </xsl:template>

    </xsl:stylesheet>

     

  • Almir Vereget 62 posts 150 karma points
    Nov 11, 2010 @ 22:05
    Almir Vereget
    0

    Hi,

    so what exactly is not working in when block?

    In your code i see that you are calling $corURLValue variable without curly braces in the href attribute.

    That will result in not getting a property from page.

    Could that be your problem?

     

  • Kevon K. Hayes 255 posts 281 karma points
    Nov 11, 2010 @ 22:31
    Kevon K. Hayes
    0

    I actually fixed that however now all is working except one thing  The url of the of the content picker always links to the parent page id "Testing2" as shown below no matter what content node I choose in the picker

     

    Here's the updated XSLT:

    <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" xmlns:MailEngine="urn:MailEngine"
      exclude-result-prefixes="msxml
    umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes
    Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings
    Exslt.ExsltSets MailEngine "
    >


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

      
      <xsl:variable name="id" select="$currentPage/corMenuItemsID" />
      <ul>
       
      
      <xsl:for-each select="umbraco.library:GetXmlNodeById($id)/corDeptMenuItem [@isDoc]">
        
        
        <xsl:variable name="corURLValue" select="umbraco.library:Item($currentPage/@id, 'corURL')" />
        <xsl:choose>
          
          <xsl:when test="$corURLValue != ''">
            <li>
              <a href="{corURL}">
                <xsl:value-of select="@nodeName"/>
              <a>
            li>
          <xsl:when>
          
          <xsl:otherwise>
            <li>

              <a href="
    {umbraco.library:NiceUrl(corDeptMenuItemLink)}">
              <xsl:value-of select="@nodeName"/>
            <li>
    </xsl:otherwise>

      <xsl:for-each>
Please Sign in or register to post replies

Write your reply to:

Draft