Copied to clipboard

Flag this post as spam?

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


  • Barry 99 posts 187 karma points
    Oct 05, 2009 @ 18:54
    Barry
    1

    Odd /Even using position

    I have a requirement to display content in a Z fashion, e.g. Row 1, item 1 on left item 2 on right; Row 2 , item 3 on left , item 4 on right.

    For this to work I am thinking I need to use XSLT's IF condition checking for odd/even number - what would be the syntax for this? some kind of

    IF position() mod 2 = 0 or something? - not sure how to do this with XSLT

  • Tommy Poulsen 514 posts 708 karma points
    Oct 05, 2009 @ 19:02
    Tommy Poulsen
    2

    you use something like this:

    <xsl:if test="position() mod 2 = 0">
    ...

    >Tommy

     

  • Barry 99 posts 187 karma points
    Oct 05, 2009 @ 19:07
    Barry
    0

    Is there any examples that do what I want e.g

    1 >>> 2

    3 >>> 4

    5 >>> 6

    The DIVs I am forced to use are

    <Div class="row>

        <div class="first">1</div>

        <div>2</div>
    </div>

    Next row etc..

    I feel I am nearly there with the postition but strugliing with how best to do this.

  • Tommy Poulsen 514 posts 708 karma points
    Oct 05, 2009 @ 19:47
    Tommy Poulsen
    0

    out of my head it would be :

    <div>
     
    <xsl:if
    test="position() mod 2 = 0">
     
      <xsl:attribute
    name="class">first</xsl:attribute>
     
    </xsl:if>
    </div>

     

    >Tommy

     

  • Tommy Poulsen 514 posts 708 karma points
    Oct 05, 2009 @ 19:51
    Tommy Poulsen
    0

    aah, sorry, I did not read your post correctly - the previous example was a generic example

  • Tommy Poulsen 514 posts 708 karma points
    Oct 05, 2009 @ 20:02
    Tommy Poulsen
    1

    I suppose this thread will help you out on the divs

    >Tommy

  • dandrayne 1138 posts 2262 karma points
    Oct 06, 2009 @ 16:27
    dandrayne
    0

    Came up against this today, and here's the hack I came up with.  You'd probably still need to add the odd/even classes, but this will help wrap two items within a div

       <xsl:variable name="opening">&lt;li&gt;</xsl:variable>
    <xsl:variable name="closing">&lt;/li&gt;</xsl:variable>

    <div>
    <xsl:for-each select="$nodeSet/descendant::node">


    <xsl:if test="position() mod 2 != 0">
    <xsl:value-of select="$opening" disable-output-escaping="yes" />
    </xsl:if>

    <xsl:value-of select="$currentItem/@nodeName" />

    <xsl:if test="position() mod 2 = 0">
    <xsl:value-of select="$closing" disable-output-escaping="yes" />
    </xsl:if>

    </xsl:for-each>
    </div>
  • Rik Helsen 670 posts 873 karma points
    Aug 16, 2010 @ 10:44
    Rik Helsen
    0

    Does this still work in 4.5.1 ? I keep getting errors ...

    my code:

    <!-- The fun starts here -->
    <div id="companyValues">
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
    <div class="companyValueItem">
       <xsl:if test="number(position()) mod 2 != 0">
            a
       </xsl:if>
                                                               
       <xsl:if test="number(position()) mod 2 = 0">
           b
       </xsl:if>

      <div class="companyValuesImage">
      <img>
     <xsl:attribute name="src">
       <xsl:value-of select="umbraco.library:GetMedia(./image, false() )/umbracoFile" />
     </xsl:attribute>

    My error:

    Error occured
    System.OverflowException: Value was either too large or too small for an Int32.


    at System.Convert.ToInt32(Double value)
    at System.Double.System.IConvertible.ToInt32(IFormatProvider provider)
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument,
    XmlResolver dataSources, XsltArgumentList argumentList,
    XmlSequenceWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument,
    XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter
    writer)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable
    input, XsltArgumentList arguments, XmlWriter results, XmlResolver
    documentResolver)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String
    fileName, String oldName, String fileContents, Boolean ignoreDebugging)

     

  • Rik Helsen 670 posts 873 karma points
    Aug 16, 2010 @ 14:08
    Rik Helsen
    0

    Nevermind, there was a different error in the xslt somewhere

  • Sean Dooley 289 posts 528 karma points
    Jun 07, 2011 @ 12:07
    Sean Dooley
    2

    The following snippet can be used to set the class to odd or even

    <xsl:choose>
    <xsl:when test="position() mod 2 = 0">
      <xsl:attribute name="class">even</xsl:attribute>
    </xsl:when>
    <xsl:otherwise>
    <xsl:attribute name="class">odd</xsl:attribute>
    </xsl:otherwise>
    </xsl:choose>
Please Sign in or register to post replies

Write your reply to:

Draft