Reputation: 97
I am not able to find maximum value from NrOfConvoys and annotationText nodes below is my XML file.
<InstructionListPosition>
<Instruction>
<Navigation>
<NrOfConvoys>2</NrOfConvoys>
<annotationText>5</annotationText>
</Navigation>
</Instruction>
</InstructionListPosition>
<InstructionListPosition>
<Instruction>
<Navigation>
<NrOfConvoys>20</NrOfConvoys>
<annotationText>10</annotationText>
</Navigation>
</Instruction>
</InstructionListPosition>
I want output as below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--Disable Cache-->
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="pragma" content="no-cache" />
<!--End-->
</head>
<body>
<div id="wrapper_all">
<table style="width:100%">
<tr>
<th>Sr. Num</th>
<th>Maximum value</th>
</tr>
<tr>
<td>1</td>
<td>5</td>
</tr>
<tr>
<td>2</td>
<td>20</td>
</tr>
</table>
</div>
</body>
</html>
I want output as shown above, please can you provide a best solution. I am using XSLT1.0.
Please help me, Thanks.
Upvotes: 0
Views: 170
Reputation: 3435
use this:
<xsl:for-each select="InstructionListPosition">
<tr>
<td>
<xsl:value-of select="position()"/>
</td>
<td>
<xsl:for-each
select=".//Navigation/*[self::NrOfConvoys or self::annotationText]">
<xsl:sort select="." order="descending"/>
<xsl:if test="position()=1">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>
See transformation at https://xsltfiddle.liberty-development.net/gWmuiJ1/1
Upvotes: 1