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 17, 2010 @ 16:48
    Kevon K. Hayes
    0

    Get Property based on if property is null "" or not

    I have a Parent Node that represents a Menu and all the childnodes of Menu are "Menu Items". Each Menu Item has 2 properties: 

    1) Content Picker (alias is "corCPURL")

    2) Textstring (alias is "corURL")

    I would to create an xslt macro that gets the value of "corCPURL" if "cpURL" is null or equal to "".

    Below is the xslt I have so far any help would be appreciated.

    I have a Parent Node that represents a Menu and all the childnodes of Menu are "Menu Items". Each Menu Item has 2 properties: 

    1) Content Picker (alias is "corCPURL")

    2) Textstring (alias is "corURL")

    I would to create an xslt macro that gets the value of "corCPURL" if "cpURL" is null or equal to "".

    Below is the xslt I have so far any help would be appreciated.

    <xsl:template match="/">
      <!--This gets the ID of the MenuItemContainer-->
    <xsl:variable name="id" select="$currentPage/corMenuID" />
    <ul>   
    <!--- Getting the Menu Items in the Container-->
    <xsl:for-each select="umbraco.library:GetXmlNodeById($id)/corMenuItem [@isDoc]">
    <!-- Setting variable to get the text value from corURL property --><xsl:variable name="corURLValue" select="umbraco.library:Item($currentPage/@id, 'corURL')" />

        <xsl:choose>
          <!-- if the value of the corCPURL is null or "" output the value of corURL property-->
          <xsl:when test="$corURLValue != ''">
            <li>
              <a href="{corURL}">
                <xsl:value-of select="@nodeName"/>
              </a>
            </li>
          </xsl:when>
          <!-- otherwise output the URL from the content picker corCPURL-->
          <xsl:otherwise>
            <li>
              <a href="umbraco.library:NiceUrl(corCPURL)">
              <xsl:value-of select="@nodeName"/>
              </a>
            </li>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </ul>
    </xsl:template>

     

     

     

     

  • Søren Tidmand 129 posts 366 karma points
    Nov 20, 2010 @ 21:19
    Søren Tidmand
    2

    Hi Kevon.

    I've tried to narrow down your wish to the following lines of code. I hope it solves your problem. Otherwise get back to me.

    All the best,

    Søren

     

    <!-- This gets the ID of the MenuItemContainer -->

    <xsl:variable name="menuRoot" select="umbraco.library:GetXmlNodeById($currentPage/corMenuID)" />

    <xsl:template match="/">

    <ul>

    <!--- Getting the Menu Items in the Container-->

    <xsl:apply-templates select="$menuRoot/corMenuItem" />

     

    </ul>

    </xsl:template>

    <!-- catch alle menu items where corURL isn't empty -->

    <xsl:template match="corMenuItem[corURL!='']">

    <li>

    <!-- as these URL's probably will point to external web pages, I've included target="_blank" -->

    <a href="{corURL}" target="_blank" title="{@nodeName}"><xsl:value-of select="@nodeName" /></a>

    </li>

    </xsl:template>

    <xsl:template match="*">

    <li>

    <!-- otherwise output the URL from the content picker corCPURL -->

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

     

    </li>

    </xsl:template>

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

    Output is blank... Looks like I'll be recreating this macro using .NET.

  • Søren Tidmand 129 posts 366 karma points
    Nov 23, 2010 @ 23:45
    Søren Tidmand
    0

    Hi Kevon,

    I replicated your setup and had it working nicely. If you want you could send me login credentials for your Umbraco and I will help you make it work. Please mail me at media AT tidmand DOT com.

    Best regards,

    Søren

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

    OK I'll try it once again.  Did you wrap your solution in an xsl:template? I was wondering because you have 3?.  

  • Søren Tidmand 129 posts 366 karma points
    Nov 24, 2010 @ 01:16
    Søren Tidmand
    0

    Yep. You have to wrap it in an xslt, so place the above written code between

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

    <xsl:param name="currentPage"/>

    and

    </xsl:stylesheet>

    and see if that does the trick.

    If you need to be sure that there is an output at all from the variable, you could try to make a copy-of like this

    <xsl:template match="/">
    <xsl:copy-of select="umbraco.library:GetXmlNodeById($currentPage/corMenuID)" />
    <ul> ......

    and put it right after the xsl:template and before the ul. This will output the xml structure based on the id picked from alias "corMenuID" of the currentPage.

    Please let me know how it goes.

    /Søren

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

    I emailed you the URL and credentials... let me know where my mistake was.

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

    FYI, anyone following this thread.  If you change your alias names for your properties, do yourself a favor and refresh the XML cache by re-publishing dependent nodes or republish the entire site.  If you do not do this the side effects will be your Macros won't render.  Obvious now wasn't before!

Please Sign in or register to post replies

Write your reply to:

Draft