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.
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.
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)
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"!
"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
E.g.:
Any one know how I accomplish this?
/Lars Mortensen
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.
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
you can use position()
div content here
Petr
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(List
1 content, InstructionFlags flags) <br /> at System.Xml.Xsl.Xslt.XsltLoader.LoadLiteralResultElement(Boolean asStylesheet) <br /> at System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List
1 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
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
just noticed a typo in that, attirbute should be attribute, but umbraco should flag it up if you paste it right in.
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
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
is working on a reply...