Copied to clipboard

Flag this post as spam?

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


  • Chau 66 posts 97 karma points
    Oct 03, 2009 @ 05:10
    Chau
    0

    dude, there's gotta be a better way - incrementing

    4.x
    asp 2.x
    windows 2003 server, iis 6.x

    Is there a better way to write this. I'd like to create a variable that was incremented until it hit a certain number, but then also be able to use that variable to be part of the data call. For example variable 'num' would be added onto 'sliderImage' to make 'sliderImage + num' for sliderImage01, num would increment and then I'd get sliderImage02, etc.

    I know how to make the variable and I can probably figure out how to increment it, but how to I integrate it with the [@alias = 'sliderImage01'] part???

    Thanks in advance.

    <?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: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 tagsLib BlogLibrary ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <!-- start writing XSLT -->
    <div id="slider_images">
     <div id="slider">
      <ul>
       <xsl:if test="string-length($currentPage/data [@alias = 'sliderImage01']) != 0">
        <li>
         <a>
          <xsl:choose>
           <xsl:when test="string-length($currentPage/data [@alias = 'sliderLink01']) != 0">
            <xsl:attribute name="href">
             <xsl:value-of select="$currentPage/data [@alias = 'sliderLink01']"/>
            </xsl:attribute>
           </xsl:when>
           <xsl:otherwise>
            <xsl:attribute name="href">#nogo</xsl:attribute>
           </xsl:otherwise>
          </xsl:choose>   
          <img>
           <xsl:attribute name="src">
            <xsl:value-of select="$currentPage/data [@alias='sliderImage01']"/>
           </xsl:attribute>
          </img>
         </a>
        </li>
       </xsl:if>
       <xsl:if test="string-length($currentPage/data [@alias = 'sliderImage02']) != 0">
        <li>
         <a>
          <xsl:choose>
           <xsl:when test="string-length($currentPage/data [@alias = 'sliderLink02']) != 0">
            <xsl:attribute name="href">
             <xsl:value-of select="$currentPage/data [@alias = 'sliderLink02']"/>
            </xsl:attribute>
           </xsl:when>
           <xsl:otherwise>
            <xsl:attribute name="href">#nogo</xsl:attribute>
           </xsl:otherwise>
          </xsl:choose>   
          <img>
           <xsl:attribute name="src">
            <xsl:value-of select="$currentPage/data [@alias='sliderImage02']"/>
           </xsl:attribute>
          </img>
         </a>
        </li>
       </xsl:if>
       <xsl:if test="string-length($currentPage/data [@alias = 'sliderImage03']) != 0">
        <li>
         <a>
          <xsl:choose>
           <xsl:when test="string-length($currentPage/data [@alias = 'sliderLink03']) != 0">
            <xsl:attribute name="href">
             <xsl:value-of select="$currentPage/data [@alias = 'sliderLink03']"/>
            </xsl:attribute>
           </xsl:when>
           <xsl:otherwise>
            <xsl:attribute name="href">#nogo</xsl:attribute>
           </xsl:otherwise>
          </xsl:choose>   
          <img>
           <xsl:attribute name="src">
            <xsl:value-of select="$currentPage/data [@alias='sliderImage03']"/>
           </xsl:attribute>
          </img>
         </a>
        </li>
       </xsl:if>
       <xsl:if test="string-length($currentPage/data [@alias = 'sliderImage04']) != 0">
        <li>
         <a>
          <xsl:choose>
           <xsl:when test="string-length($currentPage/data [@alias = 'sliderLink04']) != 0">
            <xsl:attribute name="href">
             <xsl:value-of select="$currentPage/data [@alias = 'sliderLink04']"/>
            </xsl:attribute>
           </xsl:when>
           <xsl:otherwise>
            <xsl:attribute name="href">#nogo</xsl:attribute>
           </xsl:otherwise>
          </xsl:choose>   
          <img>
           <xsl:attribute name="src">
            <xsl:value-of select="$currentPage/data [@alias='sliderImage04']"/>
           </xsl:attribute>
          </img>
         </a>
        </li>
       </xsl:if>
       <xsl:if test="string-length($currentPage/data [@alias = 'sliderImage05']) != 0">
        <li>
         <a>
          <xsl:choose>
           <xsl:when test="string-length($currentPage/data [@alias = 'sliderLink05']) != 0">
            <xsl:attribute name="href">
             <xsl:value-of select="$currentPage/data [@alias = 'sliderLink05']"/>
            </xsl:attribute>
           </xsl:when>
           <xsl:otherwise>
            <xsl:attribute name="href">#nogo</xsl:attribute>
           </xsl:otherwise>
          </xsl:choose>   
          <img>
           <xsl:attribute name="src">
            <xsl:value-of select="$currentPage/data [@alias='sliderImage05']"/>
           </xsl:attribute>
          </img>
         </a>
        </li>
       </xsl:if>
       <xsl:if test="string-length($currentPage/data [@alias = 'sliderImage06']) != 0">
        <li>
         <a>
          <xsl:choose>
           <xsl:when test="string-length($currentPage/data [@alias = 'sliderLink06']) != 0">
            <xsl:attribute name="href">
             <xsl:value-of select="$currentPage/data [@alias = 'sliderLink06']"/>
            </xsl:attribute>
           </xsl:when>
           <xsl:otherwise>
            <xsl:attribute name="href">#nogo</xsl:attribute>
           </xsl:otherwise>
          </xsl:choose>   
          <img>
           <xsl:attribute name="src">
            <xsl:value-of select="$currentPage/data [@alias='sliderImage06']"/>
           </xsl:attribute>
          </img>
         </a>
        </li>
       </xsl:if>
      </ul>
     </div> 
    </div>
    </xsl:template>
    </xsl:stylesheet> 
  • Wayne 13 posts 33 karma points
    Oct 03, 2009 @ 10:44
    Wayne
    0

    Hi Chau,

    I think you could define a recursive template.

    <xsl:template name="for.loop">
        <xsl:param name="i">1</xsl:param>
        <xsl:if test="$num &lt; 10">
            <xsl:value-of select="$i"/>
            <xsl:call-template name="for.loop">
                <xsl:with-param name="i">
                    <xsl:value-of select="$i + 1">
                </xsl:with-param>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>


    And then call it in your main template.

    <xsl:call-template name="for.loop" />

    The above call should output 123456789.

     

  • Wayne 13 posts 33 karma points
    Oct 03, 2009 @ 10:46
    Wayne
    0

    Sorry, there is a typo in the recursive template. It should be

    <xsl:template name="for.loop">
        <xsl:param name="i">1</xsl:param>
        <xsl:if test="$i &lt; 10">
            <xsl:value-of select="$i"/>
            <xsl:call-template name="for.loop">
                <xsl:with-param name="i">
                    <xsl:value-of select="$i + 1" />
                </xsl:with-param>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
  • bob baty-barr 1180 posts 1294 karma points MVP
    Oct 04, 2009 @ 05:14
    bob baty-barr
    0

    you could just append with position() when looping through the for-each loop...

  • Chris Koiak 700 posts 2626 karma points
    Oct 04, 2009 @ 10:25
    Chris Koiak
    0

    Have you thought about not implementing this as multiple similarly named fields, but instead using the 'Repeatable Custom Content' datatype http://our.umbraco.org/projects/repeatable-custom-content

    This would make looping through the field values much easier as they would be represented as child nodes.

    Chris

  • Chau 66 posts 97 karma points
    Oct 04, 2009 @ 17:43
    Chau
    0

    Hey Wayne, thanks for your input I will try it out and give it a go.

    Bob, I don't really understand your statement... I'm new at this. Can you give me an example?

    Chris, the repeatable custom content looks awesome. Why isn't this part of the umbraco base???

    Thanks all!

  • Chau 66 posts 97 karma points
    Oct 06, 2009 @ 06:55
    Chau
    0

    Chris, the problem that I have with the repeatable custom content is the fact that it require net3.5. Any other ideas? BTW Wayne you help me a ton! Thanks.

  • Wayne 13 posts 33 karma points
    Oct 06, 2009 @ 19:00
    Wayne
    0

    I faced the .net3.5 problem also. It seems that there is no solution currently. Maybe you could use child document instead of repeatable property.

Please Sign in or register to post replies

Write your reply to:

Draft