I am very new to XML and XSLT but I am trying to create a HTML page that loops through a varying length of steps and produces a list in HTML.
The XML looks something like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<module>
<name ID="SDCModule002">
<role>SDC</role>
<modNum>002</modNum>
<title>Test</title>
<audience>me</audience>
<numSteps>7</numSteps>
<steps>
<step1>Do this 1</step1>
<step2>Do this 2</step2>
<step3>Do this 3</step3>
<step4>Do this 4</step4>
<step5>Do this 5</step5>
<step6>Do this 6</step6>
<step7>Do this 7</step7>
</steps>
</name>
<name ID="SDCModule003">
<role>SDC</role>
<modNum>003</modNum>
<title>Hi</title>
<audience>you</audience>
<numSteps>4</numSteps>
<steps>
<step1>Hi</step1>
<step2>There</step2>
<step3>You</step3>
<step4>Guys</step4>
</steps>
</name>
</module>
</xml>
I have it so the information like Title, audience, task etc. are displayed for the module I am searching so that works.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/xml">
<html>
<head>
<title><xsl:value-of select="module/name[@ID='SDCModule001']/title "/></title>
</head>
<xsl:apply-templates select="module/name[@ID='SDCModule001']"/>
</body>
</html>
</xsl:template>
<xsl:template name="stepList" match="name">
<div id= "info">
<center>
<font face="verdana" size="2"><b><center><xsl:value-of select="title" /></center></b></font>
<hr></hr>
<xsl:value-of select="audience" />
<p></p>
<xsl:value-of select="numSteps" />
</center>
</div>
</xsl:template>
</xsl:stylesheet>
I think I need to have a <xsl:for-each>
that lists the steps in an ordered list, so SDCModule002 will have 7 steps, and SDCModule003 will only have 4, or do I just get the values of all child nodes of the parent <steps>
?
I don't want to do 15 if statements saying "if numSteps is 1, then do this.... if numSteps is 2, then do that" etc... I can and it would work but I am not sure if there is a more efficient way of doing this.
Edited
The expected results would be like this:
Module: SCDModule001 Title: Test Audience: Me Steps: 1. Do this 1 2. Do this 2 3. Do this 3 4. Do this 4 6. Do this 5 7. Do this 6 8. Do this 7