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

  • SEARCH
  • Home
  • 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 8506765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:40:55+00:00 2026-06-11T02:40:55+00:00

The problem is I want to distinguish same elements name with different situation. For

  • 0

The problem is I want to distinguish same elements name with different situation. For example:

<element>Hello StackOverFlow</element>
<element>
  <group>
     <ge>hello g1</ge>
     <ge>hello g2</ge>
  </group>
  <group>
     <ge>hello g3</ge>
     <ge>hello g4</ge>
  </group>
</element>

I want to have elements with text convert into

<div class="text_element">Hello StackOverFlow</div>

and for those elements with child nodes:

<div class="element">
  <ul class="group">
     <li>hello g1</li>
     <li>hello g2</li>
  </ul>
  <ul class="group">
     <li>hello g3</li>
     <li>hello g4</li>
  </ul>
</div>

So, the problem is how can I distinguish these two kind of elements in writing the template?

  • 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-11T02:40:56+00:00Added an answer on June 11, 2026 at 2:40 am

    You can use count the descendant elements to see whether or not it has children, e.g. count(descendant::group)=0

    The XSLT (assuming a root node xml on your input):

    <xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="html" version="1.0" indent="yes"/>
    
        <xsl:template match="/xml">
            <xsl:apply-templates select="element"/>
        </xsl:template>
    
        <!-- No children -->
        <xsl:template match="element[count(descendant::group)=0]">
            <div class="text_element">
                <xsl:value-of select="text()"/>
            </div>
        </xsl:template>
    
        <!-- With children -->
        <xsl:template match="element[count(descendant::group)&gt;0]">
            <div class="element">
                <xsl:apply-templates select="group"/>
            </div>
        </xsl:template>
    
        <xsl:template match="group">
            <ul class="group">
                <xsl:apply-templates select="ge"/>
            </ul>
        </xsl:template>
    
        <xsl:template match="ge">
            <li>
                <xsl:value-of select="text()"/>
            </li>
        </xsl:template>
    
    </xsl:stylesheet>
    

    Gives the output

    <div class="text_element">Hello StackOverFlow</div>
    <div class="element">
      <ul class="group">
        <li>hello g1</li>
        <li>hello g2</li>
      </ul>
      <ul class="group">
        <li>hello g3</li>
        <li>hello g4</li>
      </ul>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Problem I want to press a key when I have a line highlighted
I have a problem want to know answer, Why the following code will print
I have the follow problem. This is the situation i've got when user login
I want to have the same command when I click the Cancel button or
Problem I want to display a form that will have a variable amount of
Problem I want to use the interactive debugger with IntelliJ. Unfortunately, I can't convince
Problem: I want to add headers in the middle of a gridview databind. I
Problem: I want to list n number of games from each genre (order not
Problem: I want my unicode characters to be stored on disk as (rather tan
Problem: I want disparate sections of my code to be able to access a

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.