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 8045691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:37:22+00:00 2026-06-05T05:37:22+00:00

I am starting doing with xml and xslt, I also read some tutorials etc..

  • 0

I am starting doing with xml and xslt, I also read some tutorials etc.. and according these as I understand this xml:

<?xml version="1.0"?>  
<Menu>  
    <Accounts type="menu" label="Accounts">  
        <ListUsers type="cmd" label="List users">  
            <cmd>HAha</cmd>  
        </ListUsers>  
        <AddUsers type="cmd" label="Add users">  
            <cmd></cmd>  
        </AddUsers>  
        <DeleteUsers type="cmd" label="Delete users">  
            <cmd></cmd>  
        </DeleteUsers>  
    </Accounts>  
    <Hardware type="menu" label="Hardware">  
        <ListDisks type="cmd" label="List disks">  
            <cmd></cmd>  
        </ListDisks>  
    </Hardware>  
    <Network type="menu" label="Network"></Network>  
    <Filesystem type="menu" label="Filesystem"></Filesystem>  
</Menu>

and this xslt:

<?xml version="1.0"?>  
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
<xsl:template match="/*">   
    <xsl:apply-templates select="*"/>  
</xsl:template>  
<xsl:template match="*">  
    <div><xsl:value-of select="@label"/></div>  
</xsl:template>   
</xsl:stylesheet>

Should output labels of all elements, but it didn’t… What I am missing, could you correct and explain me please, thanks.

  • 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-05T05:37:23+00:00Added an answer on June 5, 2026 at 5:37 am

    There are two problems with this code:

    <xsl:template match="*">       
      <div>
        <xsl:value-of select="@label"/>
      </div>   
    </xsl:template>
    
    1. Elements that aren’t children of the top element (or the top element itself) are not processed at all. To correct this, a new instruction should be appended to the body of the template — for example: <xsl:apply-templates select="*"/>

    2. Elements that don’t have a label attribute will generate an empty <div>. This can be avoided if a proper template match pattern is used so that the template is selected only for elements that do have this attribute.

    Here is a complete solution and it can be as short and simple as:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="*[@label]">
         <div><xsl:value-of select="@label"/></div>
       <xsl:apply-templates select="*"/>
     </xsl:template>
     <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document:

    <Menu>
        <Accounts type="menu" label="Accounts">
            <ListUsers type="cmd" label="List users">
                <cmd>HAha</cmd>
            </ListUsers>
            <AddUsers type="cmd" label="Add users">
                <cmd></cmd>
            </AddUsers>
            <DeleteUsers type="cmd" label="Delete users">
                <cmd></cmd>
            </DeleteUsers>
        </Accounts>
        <Hardware type="menu" label="Hardware">
            <ListDisks type="cmd" label="List disks">
                <cmd></cmd>
            </ListDisks>
        </Hardware>
        <Network type="menu" label="Network"></Network>
        <Filesystem type="menu" label="Filesystem"></Filesystem>
    </Menu>
    

    the wanted, correct result is produced:

    <div>Accounts</div>
    <div>List users</div>
    <div>Add users</div>
    <div>Delete users</div>
    <div>Hardware</div>
    <div>List disks</div>
    <div>Network</div>
    <div>Filesystem</div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am starting doing some directX programming. I am using this tutorial that I
I've been starting doing some Java and JSP and now, I'm stuck. I'm not
I'm starting to use boost::serialization on XML archives. I can produce and read data,
Starting a new GWT application and wondering if I can get some advice from
Starting this morning, if I try to write in the following method using autocomplete
Starting this morning my Eclipse indigo have projects and files with gray light color.
Starting from this Question I discovered that using the powershell.exe.config to load .net Framework
I am developing an application in which I am doing XML parsing. I found
I'm starting to use lxml in Python for processing XML/XSL documents, and in general
Starting with a .csproj which defines various xml Content files. Have code generation Target

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.