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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:06:05+00:00 2026-06-13T02:06:05+00:00

I am trying to learn xslt and i am working an xml which looks

  • 0

I am trying to learn xslt and i am working an xml which looks like this.

<Beats>
 <Beat>
   <Personal type="set">
      <Usages type="box">
       1233
      </Usages>
      <NonUsages type="box">
       4122
      </NonUsages>
   </Personal>

   <NonPersonal type="unset">
      <Damages type="box">
       6466
      </Damages>
      <NonDamages type="box">
       5544
      </NonUsages>
   </NonPersonal>

   <Confidential type="set">
      <Discounts type="box">
       1233
      </Discounts>
      <NonDiscounts type="box">
       4122
      </NonDiscounts>
   </Confidential>

 </Beat>
</Beats>

My Current aim is to just print out the numbers inside the inner tags. But i cannot use the names of the tags as selectors as only the attribute ‘type’is of importance. I tried using the following xslt. But it didnt seem to work.

<xsl:output method="text"/>
<xsl:template match="*">
<html>
<body>
<h2> Test</h2>
<xsl:for-each select="//Beats/Beat/[@type='set']">
   <xsl:value-of select="[@type='box'] />
   <br/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

What am i doing wrong ?

And one more thing i couldnt figure out was how to get the name of tags while using attributes as selectors. Instead of

<xsl:value-of select="[@type='box'] />

which gives whats inside the tag; what can i use to get the name of the tag which contains this ‘type=box’ attribute ? (For. eg Usages, NonUsages, etc..)

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

    This transformation is intended to only provide the necessary corrections to your original transformation:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
    
        <xsl:template match="/">
            <html>
                <body>
                    <h2> Test</h2>
                    <xsl:for-each select="/*/*/*[@type='set']/*[@type='box']">
                        <xsl:value-of select="." />
                        <br/>
                    </xsl:for-each>
                </body>
            </html>
        </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document (after correcting it to make it well-formed XML document):

    <Beats>
     <Beat>
       <Personal type="set">
          <Usages type="box">
           1233
          </Usages>
          <NonUsages type="box">
           4122
          </NonUsages>
       </Personal>
    
       <NonPersonal type="unset">
          <Damages type="box">
           6466
          </Damages>
          <NonDamages type="box">
           5544
          </NonDamages>
       </NonPersonal>
    
       <Confidential type="set">
          <Discounts type="box">
           1233
          </Discounts>
          <NonDiscounts type="box">
           4122
          </NonDiscounts>
       </Confidential>
     </Beat>
    </Beats>
    

    the (what I guess is) wanted result is produced:

    <html>
       <body>
          <h2> Test</h2>
           1233
          <br/>
           4122
          <br/>
           1233
          <br/>
           4122
          <br/>
       </body>
    </html>
    

    and it is displayed in the browser as:

    Test

    1233

    4122

    1233

    4122


    On your second question:

    And one more thing i couldnt figure out was how to get the name of
    tags while using attributes as selectors. Instead of

    <xsl:value-of select="[@type='box'] />
    

    You want something as:

    <xsl:for-each select="/*/*/*[@type='set']/*[@type='box']">
      <xsl:value-of select="name()"/>
      <xsl:text> : </xsl:text>
      <xsl:value-of select="." />
      <br/>
    </xsl:for-each>
    

    The complete transformation now becomes:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
    
        <xsl:template match="/">
            <html>
                <body>
                    <h2> Test</h2>
                    <xsl:for-each select="/*/*/*[@type='set']/*[@type='box']">
                      <xsl:value-of select="name()"/>
                       <xsl:text> : </xsl:text>
                        <xsl:value-of select="." />
                        <br/>
                    </xsl:for-each>
                </body>
            </html>
        </xsl:template>
    </xsl:stylesheet>
    

    and when it is applied on the same XML document (above), the result is:

    <html>
       <body>
          <h2> Test</h2>Usages : 
           1233
          <br/>NonUsages : 
           4122
          <br/>Discounts : 
           1233
          <br/>NonDiscounts : 
           4122
          <br/>
       </body>
    </html>
    

    and this is displayed by the browser as:

    Test

    Usages :
    1233

    NonUsages :
    4122

    Discounts :
    1233

    NonDiscounts :
    4122

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to learn about php's arrays today. I have a set of arrays like
I've been trying to learn how to code in xslt and currently am stuck
Trying to learn a bit about PDO and is going through this tutorial .
I am trying to learn XSLT but I work best by example. I want
I am trying to learn xslt but have no good tutorials where i can
I'm trying to learn XSLT (for some holiday coding fun). I think I now
I am trying to learn XSLT and having some issues. I would think that
I am trying learn more about JSP expression evaluations. How and which variables are
trying to learn and practice arrays but I have a problem with this small
Im trying to learn glib/gtk. I wrote little code which prints files in directory

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.