Copied to clipboard

Flag this post as spam?

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


  • trfletch 595 posts 571 karma points
    Jul 20, 2011 @ 11:22
    trfletch
    0

    Check whether node is published in XSLT

    Hi all,

    I have an Umbraco 4.7 website and I have created the following XSLT to list out some "featured" nodes, I am selecting the "featured" nodes using "uComponents:Xpath checkbox list" which only allows you to select published nodes. This is all works great apart from when a user unpublishes or deletes one the nodes that has been selected as "featured" which causes my XSLT to throw an error. I assume I need to add in some type of IF statement or something into the for:each that checks for only published nodes but I do not know how to do this. Can someone please help? My XSLT so far is:

    <ul>
     
     <xsl:for-each select="umbraco.library:GetXmlNodeById(1076)/featuredProperties/XPathCheckBoxList/nodeId">
        <xsl:sort select="randomTools:GetRandom(0,count(umbraco.library:GetXmlNodeById(1076)/featuredProperties/XPathCheckBoxList/nodeId))" order="descending" />
     <xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)" />
      <xsl:variable name="mediaId" select="number($node/homepageImage)" />
        <li>
     
          <div class="featuredProperty">
            <div class="image">
              <xsl:if test="$mediaId &gt; 0">
                <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />        
                <img>
                  <xsl:attribute name="src">
                    <xsl:value-of select="$mediaNode/umbracoFile"/>
                  </xsl:attribute>
                  <xsl:attribute name="alt">
                  </xsl:attribute>
                </img>
              </xsl:if>
            </div>
         
            <div class="heading">
            <xsl:value-of select="$node/heading"/>
            </div>
            <div class="price">
              £<xsl:value-of select="$node/price"/>pcm
            </div>
            <div class="description">
              <xsl:value-of select="$node/briefDescription"/>
            </div>
            <div class="line">
              <xsl:comment><!-- --></xsl:comment>
            </div>
            <div class="link">
              <a href="{umbraco.library:NiceUrl($node/@id)}">find out more</a>
            </div>
     
          </div>
        </li>
      </xsl:for-each >
      </ul>
  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Jul 20, 2011 @ 13:02
    Jan Skovgaard
    1

    Hi Trevor

    I think you should look into something like selecting the nodes where the @nodeName attribute is in fact not empty for instance

    Like this   <xsl:variable name="mediaId" select="number($node/homepageImage[@nodeName !=''])" />

    I'm a bit unsure here since I can't remember what the XML looks like for media in 4.7 as I write this, but it's something like that you need to look into.

    If you want further help on this, then please post a dump of the xml you get returned from the $mediaid variable :-)

    /Jan

  • trfletch 595 posts 571 karma points
    Jul 20, 2011 @ 14:47
    trfletch
    0

    Hi Jan,

    Thanks for the response, from what you suggested I managed to come up with the following IF statement which appears to resolve my issue:

    <xsl:if test="$node/@nodeName !=''">

     

    So my full XSLT is now:

    <ul>
     
     <xsl:for-each select="umbraco.library:GetXmlNodeById(1076)/featuredProperties/XPathCheckBoxList/nodeId">
        <xsl:sort select="randomTools:GetRandom(0,count(umbraco.library:GetXmlNodeById(1076)/featuredProperties/XPathCheckBoxList/nodeId))" order="descending" />
     <xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)" />
      <xsl:variable name="mediaId" select="number($node/homepageImage)" />

    <xsl:if test="$node/@nodeName !=''">

        <li>
     
          <div class="featuredProperty">

            <div class="image">
              <xsl:if test="$mediaId &gt; 0">
                <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />        

                <img>
                  <xsl:attribute name="src">
                    <xsl:value-of select="$mediaNode/umbracoFile"/>
                  </xsl:attribute>
                  <xsl:attribute name="alt">
                  </xsl:attribute>
                </img>
              </xsl:if>
            </div>
         
            <div class="heading">
            <xsl:variable name="bedrooms" select="$node/bedrooms" />
            <xsl:variable name="propertyType" select="$node/propertyType" />
            <xsl:value-of select="umbraco.library:GetXmlNodeById($bedrooms)/@nodeName"/> bedroom <xsl:value-of select="umbraco.library:GetXmlNodeById($propertyType)/@nodeName"/>
            </div>
            <div class="price">
              £<xsl:value-of select="$node/price"/>pcm
            </div>
            <div class="description">
              <xsl:value-of select="$node/briefDescription"/>
            </div>
            <div class="line">
              <xsl:comment><!-- --></xsl:comment>
            </div>
            <div class="link">
              <a href="{umbraco.library:NiceUrl($node/@id)}">find out more</a>
            </div>
     
          </div>
        </li>
    </xsl:if>


      </xsl:for-each >

      </ul>

     

  • 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