Copied to clipboard

Flag this post as spam?

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


  • Matt 14 posts 34 karma points
    Jul 30, 2010 @ 11:12
    Matt
    0

    Really really simple Xslt test failing...

    Hi,

    I'm sure this is very obvious, but I can't get it to work...

    XSLT - I want to test for the existence of "related content" in my xslt, but my test breaks the xslt. I'm loading my test conditioin into a variable:

       <xsl:variable name="relatedLinksCount" select="count($currentPage/data[@alias='relatedLinks']/items/item)"/>
        Debug Value:<xsl:value-of select="$relatedLinksCount"/>

    And testing it like this:

       <xsl:if test="$relatedLinksCount &gt; 0">

    But it doesn't work (Error parsing XSLT file)... I've tried many variations, like "$relatedLinksCount = 0", and string comparisions instead, but nothing works...

    Can someone put me out of my misery?

    Thanks!

     

  • elspiko 133 posts 302 karma points
    Jul 30, 2010 @ 11:16
    elspiko
    0

    What version of umbraco are you using?

    Are you checking whether $currentPage/data[@alias='relatedLinks'] contains a value?

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jul 30, 2010 @ 11:18
    Chriztian Steinmeier
    0

    Hi Matt,

    Post somemore of the XSLT so we can see what's going on...

    /Chriztian

  • Matt 14 posts 34 karma points
    Jul 30, 2010 @ 11:23
    Matt
    0

    Hi,

    Yeah, I'm checking if there are any "related links". I'm using the custom repeatible content control so the XML looks like this:

    <items>
        <item>
            <data alias="alias1">value 1</data>
            <data alias="alias2">value 2</data>
        </item>
        <item>
            <data alias="alias1">value 3</data>
            <data alias="alias2">value 4</data>
        </item>
    </items>

    More XSLT if it helps:

        <xsl:variable name="relatedLinksCount" select="count($currentPage/data[@alias='relatedLinks']/items/item)"/>
        Value:<xsl:value-of select="$relatedLinksCount"/>

              <xsl:for-each select="$currentPage/data[@alias='relatedLinks']/items/item">
                <li>
                  <div class="image">
                    <a href="{data[@alias='relatedLinkUrl']}">
                      <img>
                        <xsl:attribute name="src">
                          <xsl:call-template name="ImageOrVideoThumbnail">
                            <xsl:with-param name="currentNode" select="umbraco.library:GetMedia(data[@alias='relatedLinkImage'],'false')"></xsl:with-param>
                            <xsl:with-param name="width">80</xsl:with-param>
                            <xsl:with-param name="height">55</xsl:with-param>
                            <xsl:with-param name="isMediaItem">true</xsl:with-param>
                            <xsl:with-param name="crop">&amp;crop=resize</xsl:with-param>
                          </xsl:call-template>
                        </xsl:attribute>
                      </img>
                    </a>
                  </div>
                  <div class="text">
                    <h4>
                      <a href="{data[@alias='relatedLinkUrl']}">
                        <xsl:value-of select="data[@alias='relatedLinkText']"/>
                      </a>
                    </h4>
                  </div>

                </li>
                
              </xsl:for-each>
              
              
            </ul>
          </div>
        </xsl:if>

  • Matt 14 posts 34 karma points
    Jul 30, 2010 @ 11:24
    Matt
    0

    Umbraco 4.1 btw.

     

    Sorry that XSLT snippet was slightly incomplete, I missed out the <xslt:if> from just before the foreach that is causing it to break:

        <xsl:if test="$relatedLinksCount &gt; 0">

    If I remove the test, it works, but adding it causes the xslt error.

  • elspiko 133 posts 302 karma points
    Jul 30, 2010 @ 11:26
    elspiko
    0

    Have you tried: 

     <xsl:variable name="relatedLinksCount" select="count($currentPage/data[@alias='relatedLinks']//item)"/>
  • Matt 14 posts 34 karma points
    Jul 30, 2010 @ 11:29
    Matt
    0

    Thanks, but that doesn't help. The thing is I can see the relatedLinksCount variable is working fine, I am outputting it and can see the value is set correctly. Its just the <xsl:if> that fails....

  • elspiko 133 posts 302 karma points
    Jul 30, 2010 @ 11:33
    elspiko
    0

    <xsl:if test="number($relatedLinksCount) &gt; 0">?

    Failing that I will bow to the XSLT wizard that is Chriztian

  • Matt 14 posts 34 karma points
    Jul 30, 2010 @ 11:34
    Matt
    0

    Oh jeez. Got it. The problem was inside my XSLT was a small bit of logic that was getting some value from some other node, and I wasn't checking this one for emptiness.

    I also omitted it from my code paste above, because I thought it was inconsequential and would add noise - so you had no chance of getting it.

    My bad, really sorry for wasting your time, and thanks for your help !

     

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft