Copied to clipboard

Flag this post as spam?

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


  • Brian Milman-Hurst 48 posts 76 karma points
    Feb 14, 2013 @ 23:00
    Brian Milman-Hurst
    0

    Display HTML on a conditional basis

    Hi guys,

    I am trying to create a credits page whereby a list is updated on the credits.aspx page ONLY if a field on an article has been completed, namely imageCredits.

    I am struggling with the XSLT code to create this condition, this isn't helped as until now I have used XSLT to only create lists and other basic structure.

    Any help would be greatly appreciated guys.

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 14, 2013 @ 23:11
    Jan Skovgaard
    0

    Hi Brian

    Could you post the XSLT you're currently working on? It will make it easier to help you out.

    Cheers,
    Jan 

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Feb 14, 2013 @ 23:34
    Chriztian Steinmeier
    0

    Hi Brian,

    It goes like this:

    To check if an element is present (i.e. actually exists in the XML):

    <xsl:if test="$currentPage[imageCredits]">

    To make sure it isn't empty (null, contains only whitespace etc.):

    <xsl:if test="$currentPage[normalize-space(imageCredits)]">

    If the opposite test makes more sense to read at that point in your code, use the not() function, e.g.:

    <xsl:if test="not($currentPage[imageCredits])">
    
    <xsl:if test="$currentPage[not(normalize-space(imageCredits))]">

    Ask away if you have other scenarios that doesn't work for you!

    /Chriztian

  • Brian Milman-Hurst 48 posts 76 karma points
    Feb 15, 2013 @ 09:29
    Brian Milman-Hurst
    0

    Cheers guys,

    That kinda makes sense to me (like I say, I am an XSLT newby!!).  Here is the code that I have so far, like I say I only want to display the info if something has been entered into the imageCredits field on the article.

     

    <?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" 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:umbraco.contour="urn:umbraco.contour" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour tagsLib BlogLibrary ">
    <xsl:output method="xml" omit-xml-declaration="yes"/>

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

      <xsl:param name="currentPage"/>

      <xsl:variable name="numberOfItems">
        <xsl:choose>
          <xsl:when test="/macro/numberOfItems != ''">
            <xsl:value-of select="/macro/numberOfItems"/>
          </xsl:when>
          <xsl:otherwise>9999999</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="imageCredits">
    <xsl:if test="not($currentPage[imageCredits])">
          
        </xsl:if>
      </xsl:variable>

      <xsl:template match="/">

      
     


        <xsl:for-each select="$currentPage/parent::*/CareerFactoryArticleHome/DateFolder/child::*/CareerFactoryTextpage [@isDoc and string(imageCredits) != '1']">
      <xsl:sort select="@createDate" order="descending" />
      <xsl:if test="position() &lt;= $numberOfItems">
      
       
    <xsl:choose>
                    <xsl:when test="string($imageCredits) != '1'">
                      <div id="">
                 <h3><href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></h3>
                 <div id="">
                      <p><xsl:value-of select="imageCredits" disable-output-escaping="yes"/></p>
                                  <br />
                       <href="{umbraco.library:NiceUrl(@id)}">Read this article</a>             
                   </div>
              </div>
      
                 </xsl:when>
                    <xsl:otherwise>
                    </xsl:otherwise>
                  </xsl:choose>
                       </xsl:if>
      
     
     </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>

Please Sign in or register to post replies

Write your reply to:

Draft