Copied to clipboard

Flag this post as spam?

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


  • Alec Colebrook-Clark 134 posts 258 karma points
    Feb 20, 2009 @ 12:44
    Alec Colebrook-Clark
    0

    XSLT fomatting

    Hi All.

    Im trying to format a for-each loop so that the results appear in a two column page.
    the way i thought of doing this wiould be a loop count however research into xslt loops show its not the correct style (being functional over procedural). Any ideas how to go about this?

    heres the code i am currently using (including my failed procedural loop count)

    [code]
    ]>

    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"
    exclude-result-prefixes="msxml umbraco.library">















    [$counter]




    [/code]

    Thanks in advance

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 25, 2009 @ 00:09
    Lee Kelleher
    0

    Hi Arekku,

    The trouble with xsl:variables is that you can't re-assign a value to it (they are variables in a sense that their data-type can be string, number, node-set, etc).

    Loops in XSLT have a natural counter in form of the "position()" function.

    Here's an example of how you could put your "photo thumbnails" into 2 columns.

    [code][/code]

    The first "if" checks if the position() is an odd number, then displays an opening "div" tag.
    The last "if" then checks if the position() is an even number, and closes the "div" tag.

    This example isn't fool-proof, as if your node-set has an odd number of items, there will be a "div" left open.

    Good luck!

    Cheers,
    - Lee

  • Alec Colebrook-Clark 134 posts 258 karma points
    Feb 27, 2009 @ 10:27
    Alec Colebrook-Clark
    0

    Thanks Lee! It seems to work perfectly (for the time being, still need to test it fully) but im sure i can modifiy what youve provided to meet what i need.

    Many thanks again

Please Sign in or register to post replies

Write your reply to:

Draft