I am trying to use XSLT to generate a dynamic class based on the number of groups it finds in the XML. For example there will be X groups in the XML, all with child nodes. I need the for each loop to dynamically create a class name based on which group number it is in the list. I can populate the group name without a problem, but I can’t find any clear information of how to append the system generated part to the class.
For example:
- groupblue class = “groupblue-1”
- grouporange class = “grouporange-2”
- groupred class = “groupred-3”
Etc etc, for every group in the XML.
I hope this makes sense and someone is able to help! Thanks in advance.
EDIT:
XML
<group>
<title>Title Content</title>
<text>Content 1</text>
</group>
<group>
<title>Title Content</title>
<text>Content 2</text>
</group>
<group>
<title>Title Content</title>
<text>Content 3</text>
</group>
HTML output
<div id="titlecontent-1">
text from group 1 content
</div>
<div id="titlecontent-2">
text from group 2 content
</div>
<div id="titlecontent-3">
text from group 3 content
</div>
This transformation:
when applied on this well-formed XML document (that wraps the provided XML fragment into a top element):
produces the wanted result: