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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:03:27+00:00 2026-05-15T14:03:27+00:00

I have an XML document that models this hierarchy of tasks: 1 Customer 1.1

  • 0

I have an XML document that models this hierarchy of tasks:

1     Customer
1.1   Product A
1.1.1 Task Alpha
1.1.2 Task Beta
1.2   Product B
1.2.1 Task Alpha
1.2.2 Task Gamma
2     Customer
2.1   Product W
2.1.1 Task Delta

Unknown number of Customers, Products, and Tasks per product. There can also be an unknown number of subtasks, so we could see this:

19.16.8.17.1 Subtask Something

The XML looks like this:

<ROWSET>
    <ROW>
        <PROJECT_CODE>Don't Care</PROJECT_CODE>
    </ROW>
    <ROW>
        <PROJECT_CODE>WBS</PROJECT_CODE>
        <TASK_DETAIL>
            <TASKS>
                <TASK>
                    <TASK_CODE>1</TASK_CODE>
                    <TASK_DESCRIPTION>Customer 1</TASK_DESCRIPTION>
                    <TASKS>
                        <TASK>
                            <TASK_CODE>1.1</TASK_CODE>
                            <TASK_DESCRIPTION>Product A</TASK_DESCRIPTION>
                            <TASKS>
                                <TASK_CODE>1.1.1</TASK_CODE>
                                <TASK_DESCRIPTION>Task Alpha</TASK_DESCRIPTION>
                                <TASKS />
                                <TASK_CODE>1.1.2</TASK_CODE>
                                <TASK_DESCRIPTION>Task Beta</TASK_DESCRIPTION>
                                <TASKS />
                            </TASKS>
                        </TASK>
                        <TASK>
                            <TASK_CODE>1.2</TASK_CODE>
                            <TASK_DESCRIPTION>Product B</TASK_DESCRIPTION>
                            <TASKS>
                                <TASK_CODE>1.2.1</TASK_CODE>
                                <TASK_DESCRIPTION>Task Alpha</TASK_DESCRIPTION>
                                <TASKS />
                                <TASK_CODE>1.2.2</TASK_CODE>
                                <TASK_DESCRIPTION>Task Gamma</TASK_DESCRIPTION>
                                <TASKS />
                            </TASKS>
                        </TASK>
                    </TASKS>
                </TASK>
                <TASK>
                    <TASK_CODE>2</TASK_CODE>
                    <TASK_DESCRIPTION>Customer 2</TASK_DESCRIPTION>
                    <TASKS>
                        <TASK>
                            <TASK_CODE>2.1</TASK_CODE>
                            <TASK_DESCRIPTION>Product W</TASK_DESCRIPTION>
                            <TASKS>
                                <TASK_CODE>2.1.1</TASK_CODE>
                                <TASK_DESCRIPTION>Task Delta</TASK_DESCRIPTION>
                                <TASKS />
                            </TASKS>
                        </TASK>
                    </TASKS>
                </TASK>
            </TASKS>
        </TASK_DETAIL>
    </ROW>
</ROWSET>

My first attempt at an XSLT is this:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="ROW">
    <xsl:apply-templates select="PROJECT_CODE[.='WBS']"/>
</xsl:template>
<xsl:template match="PROJECT_CODE">
    <h1><xsl:value-of select="."/></h1>
    <table>
        <tr>
            <th>Task Code</th>
            <th>Description</th>
        </tr>
        <xsl:for-each select="./../TASK_DETAIL/TASKS/TASK">
        <tr>
            <td><xsl:value-of select="TASK_CODE"/></td>
            <td><xsl:value-of select="TASK_DESCRIPTION"/></td>
        </tr>
            <xsl:for-each select="./TASKS/TASK">
                <tr>
                    <td><xsl:value-of select="TASK_CODE"/></td>
                    <td><xsl:value-of select="TASK_DESCRIPTION"/></td>
                </tr>
            </xsl:for-each>
        </xsl:for-each>
    </table>
</xsl:template>

As you can see, I’m taking a very naive approach to parsing this thing. I would like to list all the tasks & subtasks of my particular WBS, no matter how many levels deep it goes. How do I do that?

  • 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-15T14:03:28+00:00Added an answer on May 15, 2026 at 2:03 pm

    Looks like musikk beat me to an explanation, but here’s a demo xslt that does what I understand you want. In general, avoid xsl:for-each for most of the things you think you should use for-each for (i.e. for which you would use for-each in other languages). Instead, use apply-templates or call-templates as musikk says. Read up on modes (mode=”foo”) too if you have to process the same content several times (e.g. to generate a table of contents and then the body and then an index).

        <?xml version="1.0" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="/">
        <html>
          <body>
            <xsl:apply-templates/>
          </body>
        </html>
      </xsl:template>
      <xsl:template match="ROW[./PROJECT_CODE='WBS']">
        <h1><xsl:value-of select="PROJECT_CODE"/></h1>
        <table>
          <tr>
            <th>Task Code</th>
            <th>Description</th>
          </tr>
          <xsl:apply-templates/>
        </table>
      </xsl:template>
      <xsl:template match="TASK">
        <tr>
          <td><xsl:value-of select="TASK_CODE"/></td>
          <td><xsl:value-of select="TASK_DESCRIPTION"/></td>
        </tr>
        <xsl:apply-templates/>
      </xsl:template>
      <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    This produces:

        <html>
       <body>
          <h1>WBS</h1>
          <table>
             <tr>
                <th>Task Code</th>
                <th>Description</th>
             </tr>
             <tr>
                <td>1</td>
                <td>Customer 1</td>
             </tr>
             <tr>
                <td>1.1</td>
                <td>Product A</td>
             </tr>
             <tr>
                <td>1.2</td>
                <td>Product B</td>
             </tr>
             <tr>
                <td>2</td>
                <td>Customer 2</td>
             </tr>
             <tr>
                <td>2.1</td>
                <td>Product W</td>
             </tr>
          </table>
       </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML document that looks like this: <?xml version=1.0 encoding=utf-8?> <Schema Namespace=EDIManagement.Models.Store
I have an xml document that looks like this. <foo> <bar type=artist/> Bob Marley
I have an XML document that matches our site navigation something like this: <page
This is a tough one to google for. I have an XML document that's
I have a method that parses an xml document. I assume this method should
I have an XML document that looks like this: <file> <name>NAME_OF_FILE</name> </file> <file> <name>NAME_OF_FILE</name>
I have an XML document that I'm trying to search through. The Main structure
I have an XML document that I generate from an Entity Framework object. The
I have an XML document that I load in and try to search with
I have an XML document that includes XPath expressions that I need to use

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.