Copied to clipboard

Flag this post as spam?

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


  • Phil Crowe 192 posts 256 karma points
    Apr 06, 2010 @ 15:18
    Phil Crowe
    0

    character limiting

    Hi i need to create a simple piece of xslt that shows a div only when a text box has some text in it. If the textbox is empty then the div does not show. heres my code:

     

    <xsl:template match="/">

    <xsl:choose>

    <xsl:when test="string-length(data[@alias='linkToASP']) &gt; 0">

    <div style="text-align:center;">

    <iframe src ="{$currentPage/data[@alias='linkToASP']}" width="810" height="600" scrolling="no" style="border:none;">

       <p>Your browser does not support iframes.</p>

    </iframe>

    </div>

    </xsl:when>

    <xsl:otherwise>

    <div style="text-align:center; display:none;">

    <iframe src ="{$currentPage/data[@alias='linkToASP']}" width="810" height="600" scrolling="no" style="border:none;">

       <p>Your browser does not support iframes.</p>

    </iframe>

    </div>

    </xsl:otherwise>

    </xsl:choose>

    </xsl:template>

    For some reason the xslt doesnt seem to recognise how many characters the text field has in it. Do i need to add any additional attributes so it recognises this textfield is a datatype? The idea was the iframe would show the webpage specified in the textstring box, if theres nothing in it the iframe would not appear.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Apr 06, 2010 @ 15:27
    Sebastiaan Janssen
    2

    Hey Phil, looks like a small mistake to me, you've forgotten $currentPage when you're testing the string-length.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 06, 2010 @ 21:20
    Jan Skovgaard
    0

    Hi Phil

    As Sebastian is saying it seems like you are missing the $currentPage paramter in your sting-length. However I think you can even just write the following to check if there is a value.

    <xsl:if test="$currentPage/data [@alias = 'linkToASP'] !='0'">

    /Jan

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Apr 07, 2010 @ 08:27
    Sebastiaan Janssen
    0

    That's not right, now you're checking if the value is not '0'. But you're on the right track, if I had to rewrite this whole code, I'd do it more like this:

     <xsl:template match="/">
    
      <xsl:choose>
        <xsl:when test="data[@alias='linkToASP'] != ''">
          <div style="text-align:center;">
            <xsl:call-template name="iframe" />
          </div>
        </xsl:when>
        <xsl:otherwise>
          <div style="text-align:center; display:none;">
            <xsl:call-template name="iframe" />
          </div>
    
        </xsl:otherwise>
      </xsl:choose>
      </xsl:template>
    
      <xsl:template name="iframe">
        <iframe src ="{$currentPage/data[@alias='linkToASP']}" width="810" height="600" scrolling="no" style="border:none;">
          <p>Your browser does not support iframes.</p>
        </iframe>
      </xsl:template>
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 07, 2010 @ 08:48
    Jan Skovgaard
    0

    Hi Sebasatian

    Yes I was typing too fast there. My bad. :-)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft