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?