Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1280 posts 3990 karma points MVP 7x c-trib
    Nov 11, 2011 @ 15:14
    Bjarne Fyrstenborg
    0

    Shorten test on multiple doc types

    Hi..

    I have a simple set of multiple doctypes in the test condition in a choose element:

    <xsl:if test="$currentPage/umbHeadline != ''">
        <xsl:choose>
          <xsl:when test="$currentPage/self::Page or $currentPage/self::CartStep or $currentPage/self::NewsList or $currentPage/self::EventCalendar">
            <h1 class="articleHeading" itemprop="headline name">
              <xsl:value-of select="$currentPage/umbHeadline" disable-output-escaping="yes" />
            </h1>
          </xsl:when>
          <xsl:otherwise>
            <h1 class="articleHeading" itemprop="headline name">
              <href="{umbraco.library:NiceUrl($currentPage/@id)}"><xsl:value-of select="$currentPage/umbHeadline" disable-output-escaping="yes" /></a>
            </h1>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>

    Is there an easier way to summarize the line:

    $currentPage/self::Page or $currentPage/self::CartStep or $currentPage/self::NewsList or $currentPage/self::EventCalendar

    Bjarne

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Nov 11, 2011 @ 15:21
    Chriztian Steinmeier
    2

    Hi Bjarne,

    Yes - use templates :-)

    <xsl:template match="/">
        <xsl:apply-templates select="$currentPage[normalize-space(umbHeadline)]" />
    </xsl:template>
    
    <xsl:template match="Page | CartStep | NewsList | EventCalendar">
        <h1 class="articleHeading" itemprop="headline name">
            <xsl:value-of select="umbHeadline" disable-output-escaping="yes" />
        </h1>
    </xsl:template>
    
    <xsl:template match="*[@isDoc]" priority="-1">
        <h1 class="articleHeading" itemprop="headline name">
            <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="umbHeadline" disable-output-escaping="yes" /></a>
        </h1>
    </xsl:template>

    /Chriztian

  • Bjarne Fyrstenborg 1280 posts 3990 karma points MVP 7x c-trib
    Nov 11, 2011 @ 15:37
    Bjarne Fyrstenborg
    0

    Hi Chriztian..
    Thanks..

    So the templates replace the choose element? and the priority attribute with -1 behaves as the otherwise element?

    And I was trying with seperating the doctypes with |  .. 
    I guess I still need to wrap the  <xsl:apply-templatesselect="$currentPage[normalize-space(umbHeadline)]"/>  inside the $currentPage/umbHeadline != ''  test..

    Bjarne

  • Dan Okkels Brendstrup 101 posts 197 karma points
    Nov 11, 2011 @ 16:26
    Dan Okkels Brendstrup
    0

    No, the normalize-space() function is already ensuring that templates are applied to the $currentPage only if there is content in the umbHeadline element, so the if-statement is no longer necessary.

    As the name implies, normalize-space() normalizes whitespace in the node by stripping away leading and trailing whitespace (among other things). If there is still content left after the normalization, the predicate returns true(), and the templates are applied. Chriztian explained it quite well midway through this comment :)

  • Bjarne Fyrstenborg 1280 posts 3990 karma points MVP 7x c-trib
    Nov 11, 2011 @ 16:35
    Bjarne Fyrstenborg
    0

    Okay.. thanks for your explanation Dan ..

    Now I know that :)

    Bjarne

Please Sign in or register to post replies

Write your reply to:

Draft