Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8756399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:04:38+00:00 2026-06-13T14:04:38+00:00

I am trying to use XSLT to generate a dynamic class based on the

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:04:39+00:00Added an answer on June 13, 2026 at 2:04 pm

    This transformation:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="group">
         <div id="{translate(title, ' ', '')}-{position()}">
           <xsl:value-of select="text"/>
         </div>
     </xsl:template>
     <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    when applied on this well-formed XML document (that wraps the provided XML fragment into a top element):

    <t>
        <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>
    </t>
    

    produces the wanted result:

    <div id="TitleContent-1">Content 1</div>
    <div id="TitleContent-2">Content 2</div>
    <div id="TitleContent-3">Content 3</div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use XSLT text output to generate a file (in a file
I am trying to use XSLT to transform a XML in to flat text.
I'm trying to use XSLT to generate some XHMTL with inline PHP. I've run
I am trying to generate HTML which will display the data from XML through
i am trying to transform my xml via java/xalan (2.7.1) with org.apache.xalan.xslt.Process class I
I'm trying to use the XSLTProcessor class in php to generate xhtml from a
I'm trying to use XSLT to append context-param as last sibling. There's no common
I'm trying to use ant to use XSLT to preprocess three specific stylesheets in
I am trying to use <xsl:for-each select=@*> to grab all the attributes of a
I'm trying to use XSLT to create Edge Side Includes html blocks. Here is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.