I have a number of divs on a page. Every 6th div needs to have a different CSS class, so I'm trying to use the 'mod' function. It works when I hard code the value but not when I use an XSLT variable (of data type 'number').
I'm guessing the error is due to the placement of the <xsl:value-of /> instruction. You can only add attributes to an element that hasn't been closed or had any child-content (elements or text) written to it. Make sure that your class attribute gets generated immediately after opening the <div> element:
Use XSLT variable in XSLT operator
Hi,
I have a number of divs on a page. Every 6th div needs to have a different CSS class, so I'm trying to use the 'mod' function. It works when I hard code the value but not when I use an XSLT variable (of data type 'number').
The following code DOES work:
But this DOESN'T work:
Does anyone know how to get the XSLT variable to work?
Thanks
Try put it like this in the test:
test="(position() mod number($itemsPerLine)) = 0"
Thanks Anders, I've tried that and it gives an error "Error parsing XSLT file".
Hi Dan,
I'm guessing the error is due to the placement of the <xsl:value-of /> instruction. You can only add attributes to an element that hasn't been closed or had any child-content (elements or text) written to it. Make sure that your class attribute gets generated immediately after opening the <div> element:
(Note, I've used a shortcut - since there can only be one attribute with the name "class", if you redefine it, it'll take the new value.)
You should be able to see the reason for the error using the XSLT Visualizer...
/Chriztian
Ah, so I didn't need the line at the start:
Works perfectly now, thanks very much!
is working on a reply...