xtremeLogic
Programmer
Hi,
I have an xml file whose basic structure is:
I have created an XSL file to transform the XML into HTML but since I am new to XSL I am having a lot of trouble grouping the data and ordering it.
Basically I would like to Group the Data by the Check entity attribute: Type (which has possible values of 1-4). So if it is Type=1, I would like to output a specific title at the top of the table like "Title1" similarly for Type=2, "SomeTitle", and onwards.
Now after grouping by Type, I would like to group by the Check entity attribute: Cat (possible values of 1 or 2). Similarly I would like to output a subTitle for each Category. Finally I would like to order the end results by Grade.
Here is the portion of my XSL that I have got. I tried putting nested <xsl:for-each select="Check"><xsl:for-each select="Type"><xsl:for-each select="Cat"> but I get no output. I would greatly appreciate it if someone could kindly tell me how to get this group by working. I have looked at some online resources like Muenchian grouping and they can be confusing.
I have an xml file whose basic structure is:
Code:
<Scan>
<Check ID="100" Grade="5" Type="1" Cat="1" Rank="3"
Name="Check1" URL1="c1.html" URL2="C2.html">
<Advice>Sample summary of problem</Advice>
<Detail>
<Head>
<Col>Detail 1</Col>
<Col>Detail 2</Col>
</Head>
<Row Grade="5">
<Col>c1d1</Col>
<Col>c1d2</Col>
</Row>
<Row Grade="5">
<Col>abc:</Col>
<Col>def</Col>
</Row>
</Detail>
</Check>
.
.
.
</Scan>
Basically I would like to Group the Data by the Check entity attribute: Type (which has possible values of 1-4). So if it is Type=1, I would like to output a specific title at the top of the table like "Title1" similarly for Type=2, "SomeTitle", and onwards.
Now after grouping by Type, I would like to group by the Check entity attribute: Cat (possible values of 1 or 2). Similarly I would like to output a subTitle for each Category. Finally I would like to order the end results by Grade.
Here is the portion of my XSL that I have got. I tried putting nested <xsl:for-each select="Check"><xsl:for-each select="Type"><xsl:for-each select="Cat"> but I get no output. I would greatly appreciate it if someone could kindly tell me how to get this group by working. I have looked at some online resources like Muenchian grouping and they can be confusing.
Code:
<xsl:for-each select="Scan">
<xsl:for-each select="Check">
<table width="100%" border="0" cellspacing="0" cellpadding="10" bgcolor="#A1BDEA">
<thead>
<tr>
<td width="50" class="tableHeaderText">Score</td>
<td width="100" class="tableHeaderText">Issue</td>
<td class="tableHeaderText">Results</td>
</tr>
</thead>
<tbody>
<xsl:sort order="ascending" select="@Grade" data-type="number"/>
<tr>
<xsl:choose>
<xsl:when test="position() mod 2 = 1">
<xsl:attribute name="class">rowOdd </xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="class">rowEven</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<td align="center" valign="top">
<xsl:choose>
<xsl:when test="@Grade=1">
<xsl:for-each select="@Grade">
<img src="X_Red.gif"/>
</xsl:for-each>
</xsl:when>
<xsl:when test="(@Grade=5)">
<xsl:for-each select="@Grade">
<img src="Check_Green.gif"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</td>
<td valign="top">
<xsl:for-each select="@Name">
<xsl:value-of select="."/>
</xsl:for-each>
</td>
<td valign="top">
<xsl:for-each select="Advice">
<xsl:value-of select="."/>
</xsl:for-each>
<br/>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="200">
<xsl:for-each select="@URL1">
<a>
<xsl:attribute name="class">linkText</xsl:attribute>
<xsl:attribute name="href"><xsl:value-of select="."/></xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
What was scanned
</a>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="@URL2">
<a>
<xsl:attribute name="class">linkText</xsl:attribute>
<xsl:attribute name="href"><xsl:value-of select="."/></xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
How to correct this
</a>
</xsl:for-each>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</xsl:for-each>
</xsl:for-each>