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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:09:12+00:00 2026-05-14T15:09:12+00:00

I have a problem between XML and XSL files. In XML file, there are

  • 0

I have a problem between XML and XSL files. In XML file, there are some elements such as
*<school>
<student studentID=”12345″>
<name>Stud I</name>
<takes>CMPE471</takes>
<takes>CMPE412</takes>
<takes>CMPE100</takes>
</student>

<student studentID=”67890″>
<name>Stud II</name>
<takes>CMPE471</takes>
<takes>CMPE412</takes>
</student>

<course courseCode=”CMPE471″>
<courseName>NAME I </courseName>
<description>DESC I </description>
</course>

<course courseCode=”CMPE412″>
<courseName>NAME II </courseName>
<description>DESC II </description>
</course>

<course courseCode=”CMPE100″>
<courseName>NAME III </courseName>
<description>DESC III </description>
</course>

In XSL file,I want to reach “description” element which I specified “courseCode”.
Output should be like this,
1. Stud I
     a. CMPE471 Desc I
     b. CMPE412 Desc II
     c. CMPE100 Desc III

2. Stud II
     a. CMPE471 Desc I
     b. CMPE412 Desc II

In XSL file, I tried to write something :

<ol>
<xsl:for-each select=”/school/student”>
<xsl:sort data-type=”text” order=”ascending” select=”name”/>

<li><xsl:value-of select=”name”/>

<ol type=”a”>
<xsl:for-each select=”takes”>
<xsl:sort data-type=”text” select=”text()” order=”ascending”/>
<li>

<xsl:for-each select=”/school/course”>//PROBLEM
<xsl:value-of select=”description [@courseCode = text()]”/>//PROBLEM
</xsl:for-each>//PROBLEM

</li>
</xsl:for-each>
</ol>
</xsl:for-each>
</ol>
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-05-14T15:09:13+00:00Added an answer on May 14, 2026 at 3:09 pm

    See my XSLT 1.0 and 2.0 solution below. The problem in your code is:

    <xsl:value-of select="description [@courseCode = text()]"/>
    

    This means that you are looking for the element description whose attribute courseCode is the same as its text value. What I do is to save the course code in a variable and check for course elements whose attribute is the same as this variable.

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
      <xsl:output indent="yes" />
    
      <xsl:template match="/">
        <ol>
          <xsl:for-each select="/school/student">
            <xsl:sort data-type="text" order="ascending" select="name" />
            <li>
              <xsl:value-of select="name" />
              <ol type="a">
                <xsl:for-each select="takes">
                  <xsl:sort data-type="text" select="." order="ascending" />
                  <li>
                    <xsl:variable name="coursecode" select="." />
                    <xsl:value-of select="concat('(',.,') ')" />
                    <xsl:for-each select="/school/course[@courseCode = $coursecode]">
                      <xsl:value-of select="description" />
                    </xsl:for-each>
    
                  </li>
                </xsl:for-each>
              </ol>
            </li>
          </xsl:for-each>
        </ol>
      </xsl:template>
    </xsl:stylesheet> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 366k
  • Answers 366k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your colleague is completely wrong. He is mis-applying the fact… May 14, 2026 at 4:31 pm
  • Editorial Team
    Editorial Team added an answer Here is a custom-made console application example for you. Not… May 14, 2026 at 4:30 pm
  • Editorial Team
    Editorial Team added an answer I extracted shared_ptr from Boost to use it separately, and… May 14, 2026 at 4:30 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.