Copied to clipboard

Flag this post as spam?

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


  • Brian 77 posts 251 karma points
    Feb 11, 2015 @ 17:13
    Brian
    0

    Reference a true / false in XSLT

    Hi guys,

    I am trying to reference a true false datatype called 'pickOfTheWeek' in xslt and then display referenced info (see code below).  Unfortunately I cannot seem to get this to work.

    Here is the snippet code I am trying to select pickOfTheWeek:

    <xsl:if test="string(./pickOfTheWeek) = '1'">

    and here is the full code:

    <?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"

      exclude-result-prefixes="msxml umbraco.library">

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

     

      <xsl:param name="currentPage"/>

     

      <xsl:template match="featuredImage">

    <img src="{.}"  />

    </xsl:template>

      <xsl:template match="/">

      <xsl:variable name="excerptLength">

        <xsl:choose>

          <xsl:when test="string(/macro/excerptLength) != ''">

            <xsl:value-of select="/macro/excerptLength"/>

          </xsl:when>

          <xsl:otherwise>500</xsl:otherwise>

        </xsl:choose>

      </xsl:variable>

     <xsl:variable name="numberOfItems">

        <xsl:choose>

          <xsl:when test="/macro/numberOfItems != ''">

            <xsl:value-of select="/macro/numberOfItems"/>

          </xsl:when>

          <xsl:otherwise>2</xsl:otherwise>

        </xsl:choose>

      </xsl:variable>

        <xsl:variable name="recordsPerPage" select="1"/>

        <xsl:variable name="pageNumber">

          <xsl:choose>

            <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 1 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>

            <xsl:otherwise>

              <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>

            </xsl:otherwise>

          </xsl:choose>

        </xsl:variable>

     <xsl:for-each select="$currentPage/TheDscTeam/* [@isDoc and (umbracoNavihide)= '1']">

      <xsl:sort select="@createDate" order="descending" />

     <xsl:if test="string(./pickOfTheWeek) = '1'">

    <div class="column">

    <div class="colcontainer">

    <figure><a href="{umbraco.library:NiceUrl(@id)}"><xsl:apply-templates select="ancestor-or-self::*[normalize-space(featuredImage)][1]/featuredImage" /></a></figure>

    <h4><xsl:value-of select="@nodeName"/></h4>

    </div><!--colcontainer-->

    <p>

      <xsl:choose>

                    <xsl:when test="string($excerptLength) != '0'">

                      <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(mainContent), number($excerptLength), '...')" disable-output-escaping="yes"/>

                    </xsl:when>

                    <xsl:otherwise>

                      <xsl:value-of select="mainContent" disable-output-escaping="yes"/>

                    </xsl:otherwise>

                  </xsl:choose>

      </p>

    <a href="{umbraco.library:NiceUrl(@id)}" class="readfull">Read Full Article</a>

    </div><!--column-->

    </xsl:if>

          </xsl:for-each>

      </xsl:template>

    </xsl:stylesheet>

     

    I know XSLT is frowned on these days but alas it is all I am familiar with at present.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 11, 2015 @ 21:56
    Jan Skovgaard
    0

    Hi Brian

    Nothing wrong with using XSLT :)

    From the above code I'm a bit unsure if the context is right though...Where does the pickOfTheWeek property exist? Is it on the TheDscTeam document type or is it on a child type?

    And are you certain the it's either 1 or 0 that is returned? If so try removing the single quotes that '1' is wrapped within.

    /Jan

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies