Copied to clipboard

Flag this post as spam?

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


  • Lars Mortensen 90 posts 98 karma points
    May 28, 2009 @ 21:45
    Lars Mortensen
    0

    "For each" counter

    Hi

    Sorry if this question have been asked before, but I can't find the answer my self.

    But I would like to have some kind of count, so I can give a

    a dynamic name.

    E.g.:


    Any one know how I accomplish this?

    /Lars Mortensen

  • Tommy Poulsen 514 posts 708 karma points
    May 28, 2009 @ 21:52
    Tommy Poulsen
    0

    Unfortunately variables in xslt cannot be changed, so the obvious approach does not work.
    Instead you can sometimes use position() as a counter - giving the position of the current node in a loop.
    Alternatively you can call templates recusively using a counter as parameter, and passing the current count+1 as a argument.

    See http://blackpoint.dk/umbraco-workbench.aspx?Snippet=/umbraco-workbench/xslt/looping.aspx for inspiration.

    Tommy

  • Peter Dijksterhuis 1442 posts 1722 karma points
    May 28, 2009 @ 22:08
    Peter Dijksterhuis
    0

    If you want the div's to have a dynamic name, you could think of using the @id of the node for that. Every @id should be pretty unique, so basically you get the same effect as using a counter.

    Cheers,
    PeterD

  • Petr Snobelt 923 posts 1535 karma points
    May 28, 2009 @ 22:39
    Petr Snobelt
    0

    you can use position()


    div content here



    Petr

  • Lars Mortensen 90 posts 98 karma points
    May 29, 2009 @ 15:06
    Lars Mortensen
    0

    HI

    PeterD is correct, I don't necessarily need a count, but some unique.

    Now im just a copy/paste xslt programmer, so I can't figure out how to use it.

    Here I what I try:







    The error it gives:
    Error occured

    System.Xml.XmlException: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 19, position 237.
    at System.Xml.XmlTextReaderImpl.Throw(Exception e)
    at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr)
    at System.Xml.XmlTextReaderImpl.ParseAttributes()
    at System.Xml.XmlTextReaderImpl.ParseElement()
    at System.Xml.XmlTextReaderImpl.ParseElementContent()
    at System.Xml.Xsl.Xslt.XsltInput.ReadNextSiblingHelper()
    at System.Xml.Xsl.Xslt.XsltInput.ReadNextSibling()
    at System.Xml.Xsl.Xslt.XsltInput.MoveToFirstChild()
    at System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List1 content, InstructionFlags flags) <br /> at System.Xml.Xsl.Xslt.XsltLoader.LoadLiteralResultElement(Boolean asStylesheet) <br /> at System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List1 content, InstructionFlags flags)
    at System.Xml.Xsl.Xslt.XsltLoader.XslForEach()
    at System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List`1 content, InstructionFlags flags)
    at System.Xml.Xsl.Xslt.XsltLoader.LoadTemplate(NsDecl stylesheetNsList)
    at System.Xml.Xsl.Xslt.XsltLoader.LoadRealStylesheet()
    at System.Xml.Xsl.Xslt.XsltLoader.LoadDocument()
    at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)

    Anyone who wants to give it a shot?

    /Lars Mortensen

  • dandrayne 1138 posts 2262 karma points
    May 29, 2009 @ 15:36
    dandrayne
    0

    Try this (and use it to see what's changed from yours) ->

    [code]





    [/code]


    You seem to have a block element (div) inside an inline element (a), which is invalid html - but this isn't what you asked about so i digress!

    A good idea might when feeling around with xslt might be to get an editor with syntax highlighting. you can then usually see what has gone wrong when "the colours are weird"!

    Dan

  • dandrayne 1138 posts 2262 karma points
    May 29, 2009 @ 15:38
    dandrayne
    0

    just noticed a typo in that, attirbute should be attribute, but umbraco should flag it up if you paste it right in.

  • Petr Snobelt 923 posts 1535 karma points
    Jun 01, 2009 @ 09:02
    Petr Snobelt
    0

    If you need unique names use id attribute.


    div content here



    For mouseover use css, not inline styles or js
    http://wellstyled.com/css-nopreload-rollovers.html

    Petr

  • Lars Mortensen 90 posts 98 karma points
    Jun 03, 2009 @ 14:24
    Lars Mortensen
    0

    Hi Dan

    Thanks for the help, had to remove some line brakes though.

    I agree, it's not to pretty the code, but I'm just doing an 1:1 site migration so atm I don't care about the code as long as it works.

    But thanks for your time, to reply.

    /Lars Mortensen

Please Sign in or register to post replies

Write your reply to:

Draft