Copied to clipboard

Flag this post as spam?

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


  • Frederik T 234 posts 345 karma points
    Aug 29, 2011 @ 13:00
    Frederik T
    0

    Choose test skips directly to Otherwise

    Ok, this problem might be bigger but here goes:

    Ive described what this is about in greater detail here:
    http://our.umbraco.org/forum/developers/xslt/23187-Help-tidying-up-and-fixing-errors-with-a-List-Rotator

    Anyway, its evolved since then at works as intened, albeit with even uglier code.

    The heading for an article is in a box in the slider, and if the heading is too big it cant fit, therefor i have a test for string length to adjust the box size to accomodate the heading size.

    <xsl:choose>
     <xsl:when test="$currentPage/@level = 1">
    <div class="thumbnails">
        <ul>
          <!-- "articleFontpageLink" is a document template boolean property, checks if its true. Decides wether it should be listed or not-->
          <xsl:for-each select="$currentPage/descendant::*[@isDoc][not(umbracoNaviHide = 1)][string(articleFrontpageLink) = '1']">

          <li>
            <div class="thumb">
            <!-- Thumbnail for listed item -->
            <xsl:if test="count(current()/outputPictures) > 0">
            <img src="/ImageGen.ashx?image={current()/outputPictures[position()=1]/DAMP[@fullMedia]/mediaItem/Image/umbracoFile}&amp;width=70&amp;height=64"/>
            </xsl:if>
            <p>
              <span class="title">
                <xsl:value-of select="string(articleHeading)"/>
              </span>
              <br/>
              <!-- Text from listed item, to appear in the list itself -->
              <!-- <xsl:value-of select="umbraco.library:TruncateString(artikel-Teasertekst,70,'...')"/> -->
            </p>
            </div>
          <!-- Background image for highlighted item-->
          <a href="/ImageGen.ashx?image={current()/outputPictures[position()=1]/DAMP[@fullMedia]/mediaItem/Image/umbracoFile}&amp;width=581&amp;constrain=true"><xsl:value-of select="normalize-space('')"/></a>  
          <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="normalize-space('')"/></a>
            <xsl:choose>
              <xsl:when test="string-length('articleHeading') &gt;= 15">
                <div style="top:225px; left:0px; width:600px;">
                  <!-- Article header -->
                  <h1><a href="{umbraco.library:NiceUrl(@id)}"> Større
                  <xsl:attribute name="class">
                  <xsl:value-of select="article-color"/>
                  </xsl:attribute>
                  <xsl:value-of select="articleHeading"/>
                    
                  </a>
                  </h1>  
                  <!-- Text excerpt from article-->
                  <p><a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:value-of select="artikel-Teasertekst"/></a></p>
                </div>       
              </xsl:when>
              <xsl:otherwise>
                <div style="top:200px; left:0px; width:600px;">
                  <!-- Article header -->
                  <h1><a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:attribute name="class">
                  <xsl:value-of select="article-color"/>
                  </xsl:attribute>
                  <xsl:value-of select="articleHeading"/>
                  </a>
                  </h1>  
                  <!-- Text excerpt from article-->
                  <p><a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:value-of select="artikel-Teasertekst"/></a></p>
                </div>   
              </xsl:otherwise>
            </xsl:choose>  
          </li>
          
          </xsl:for-each>
        </ul>
        </div>
          </xsl:when>

    It was obvious that something was wrong with the test, but if i do anything else inside the "string-length" brackets, it gives an exception:

    "ystem.Xml.Xsl.XslTransformException: Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added."

    If i write string-length(articleHeading) (without the ' ' ) it gives that error, heck, it does so regardless of what i try. I must have missed something, or its just the code in general thats the problem.honestly the code above isnt all of it, i can post it if its relevant.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 29, 2011 @ 13:18
    Tom Fulton
    0

    Hi Frederik,

    The problem is that your <xsl:attribute> tag needs to be directly after the tag you wish to use it on.  So you should change this:

                  <!-- Article header -->
                  <h1><a href="{umbraco.library:NiceUrl(@id)}"> Større
                  <xsl:attribute name="class">
                  <xsl:value-of select="article-color"/>
                  </xsl:attribute>

    to this:

                  <!-- Article header -->
                  <h1><a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:attribute name="class">
                  <xsl:value-of select="article-color"/>
                  </xsl:attribute>
                   Større

    Or, if you've already done the article-color logic you can use this for shorthand:

                  <!-- Article header -->
                  <h1><a href="{umbraco.library:NiceUrl(@id)}" class="{article-color}">
              Større

    Hope this helps,

    Tom

  • Frederik T 234 posts 345 karma points
    Aug 29, 2011 @ 13:27
    Frederik T
    0

    Thank you for helping me, but i dont really understand your solution?

    (btw, the "Større" is just there so i can see of it hits the "when" condition, its not supposed to be there for other than testing)

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 29, 2011 @ 13:31
    Tom Fulton
    0

    Sorry for the confusion.  The issue is that your <xsl:attribute> tag needs to be DIRECTLY after the <a> tag (or whichever tag it should apply to).  You cannot have any logic, text output, etc between the tag and the <xsl:attribute> tag.

    In your original code you have the word "Større" in between the <a> and <xsl:attribute> tag.  In the fixed code I pasted, the Større text is moved after the <xsl:attribute> tag

    Does that make sense?

    -Tom

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 29, 2011 @ 13:37
    Tom Fulton
    0

    Are you still getting errors if you remove the Store text?  Or is your condition just not getting hit?

    Also as you mentioned you should change string-length('articleHeading') to remove the quotes, ie string-length(articleHeading)

    -Tom

  • Frederik T 234 posts 345 karma points
    Aug 29, 2011 @ 13:39
    Frederik T
    0

    Ok thank you, i think ive gotten a step closer but not really there. Ive removed the ' ' form the string length, it accepted that now so thats a start, but from what i can see it doesnt jump down to the otherwise now.

    <xsl:choose>
              <xsl:when test="string-length(articleHeading) &gt;= 20">
                <div style="top:225px; left:0px; width:600px;">
                  <!-- Article header -->
                  <h1><a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:attribute name="class">
                  <xsl:value-of select="article-color"/>
                  </xsl:attribute>
                  <xsl:value-of select="articleHeading"/>
                  </a>
                  </h1>  
                  <!-- Text excerpt from article-->
                  <p><a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:value-of select="artikel-Teasertekst"/></a></p>
                </div>       
              </xsl:when>
              <xsl:otherwise>
                <div style="top:200px; left:0px; width:600px;">
                  <!-- Article header -->
                  <h1><a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:attribute name="class">
                  <xsl:value-of select="article-color"/>
                  </xsl:attribute>
                  <xsl:value-of select="articleHeading"/>
                  </a>
                  </h1>  
                  <!-- Text excerpt from article-->
                  <p><a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:value-of select="artikel-Teasertekst"/></a></p>
                </div>   
              </xsl:otherwise>
            </xsl:choose
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 29, 2011 @ 13:47
    Tom Fulton
    1

    That looks fine to me.  Obviously it will only run the code in the <xsl:otherwise> if the articleHeading is < 20 characters.  Are you saying that's not happening in that case?  You could try outputting the length to debug, ie  <xsl:value-of select="string-length(articleHeading)" />

    Also, are both sets of code the same except for the <div> style?  If so there are a couple ways you could simplify it, here's a quick example:

    <div>
     <xsl:attribute name="style">
      <xsl:choose>
        <xsl:when test="string-length(articleHeading) &gt; 20">top:225px;</xsl:when>
        <xsl:otherwise>top:200px;</xsl:otherwise>
      </xsl:choose>left:0px;width:600px;
    </xsl:attribute>
    .. the rest of your code inside the div ..
    </div>

    -Tom

  • Frederik T 234 posts 345 karma points
    Aug 29, 2011 @ 13:47
    Frederik T
    0

    Ok, i think i got it now, the

    <divstyle="top:225px; left:0px; width:600px;">

    is what defines how big the box will be, and i think it somehow switched them around, dont ask me why or how, but after fiddling with the numbers, it seems that it DOES work after your suggestions, thank you!

    Now the next step is optimizing the code, actually, the code ive written above is doubled in one big choose that determines if current page is on level 1 or 2. Ive been trying to cut the choose out entirely, but defining where currentpage is doesnt work. Oh well, thats for another day, a deadline is coming up and i dont have much time left to fiddle with stuff that "works". Again thank you for your time.

Please Sign in or register to post replies

Write your reply to:

Draft