Copied to clipboard

Flag this post as spam?

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


  • Lisa Duvall 3 posts 23 karma points
    Mar 15, 2011 @ 16:51
    Lisa Duvall
    0

    Breadcrumb xslt currentpage Issue

    I am trying to use the breadcrumb template that is built in to umbraco.  I let my users select a new link name or if they leave that field blank, then it uses the pageName.  For my print currentpage section of the Breadcrumb, I would like to be able to check if the 'linkText' is not equal to null, then print the link text.  If it is null or empty then print the currentPage/@nodeName.

    Here is my code:


    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:variable name="minLevel" select="1"/>
    <xsl:template match="/">
    <xsl:if test="$currentPage/@level &gt; $minLevel">
        <ul>
                    <xsl:for-each select="$currentPage/ancestor::node [@level &gt; $minLevel and string(data [@alias='umbracoNaviHide']) != '1']">
                      <li>
                            <a href="{umbraco.library:NiceUrl(@id)}">
                                  <xsl:value-of select="@nodeName"/>
                            </a> &#187;
                      </li>
                    </xsl:for-each>
            <!-- print currentpage -->
                        <li>    <xsl:value-of select="data [@alias = 'linkText']"/>
                    <xsl:if test="data [@alias='linkText'] = ''">
                        <xsl:value-of select="$currentPage/@nodeName"/>
                    </xsl:if>
                    <xsl:if test="data [@alias='linkText'] != ''">
                        <xsl:value-of select="data [@alias='linkText']" />
                    </xsl:if>
                        </li>
          </ul>
    </xsl:if>
    </xsl:template>

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Mar 15, 2011 @ 17:29
    Michael Latouche
    0

    Hi Lisa,

    Maybe you could give some information about what exactkly is the problem you are experiencing (error, text is blank, ...)? It might help getting in the goor direction to search for.

    Cheers,

    Michael.

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Mar 15, 2011 @ 17:36
    Tim
    0

    I think the function you are looking for is string-length(). You can use that to check if a property has anything in it. You could also use a case when instead of an if (as that supports an else).

    So the code to would be:

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:variable name="minLevel" select="1"/>
    <xsl:template match="/">
    <xsl:if test="$currentPage/@level &gt; $minLevel">
        <ul>
                    <xsl:for-each select="$currentPage/ancestor::node [@level &gt; $minLevel and string(data [@alias='umbracoNaviHide']) != '1']">
                      <li>
                            <a href="{umbraco.library:NiceUrl(@id)}">
                                  <xsl:value-of select="@nodeName"/>
                            </a> &#187;
                      </li>
                    </xsl:for-each>
            <!-- print currentpage -->
                    <li>
                    <xsl:choose>
                        <xsl:when test="string-length($currentPage/data [@alias='linkText']) &gt; 0">
                            <xsl:value-of select="$currentPage/data [@alias='linkText']"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="$currentPage/@nodeName"/>
                        </xsl:otherwise>
                    </xsl:choose>
                    </li>
          </ul>
    </xsl:if>
    </xsl:template>

    Hope that helps!

  • Lisa Duvall 3 posts 23 karma points
    Mar 15, 2011 @ 18:57
    Lisa Duvall
    0

    Thank you Tim...this worked perfectly.

Please Sign in or register to post replies

Write your reply to:

Draft