Format xml using Xslt
Xml Example
<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="./Source_output.xsl"?>
<ns0:Summary xmlns:ns0="http://CM_EAI.Summary">
<Successful>
<Job_Competency>3</Job_Competency>
</Successful>
<Unsuccessful>
<Job_Competency>
<Item Name="a" ErrorMsg="not exist" />
<Item Name="b" ErrorMsg="error" />
</Job_Competency>
</Unsuccessful>
</ns0:Summary>
Xslt Example
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:msfunction="http://www.mycompany.org/ns/function" exclude-result-prefixes="msxsl msfunction">
<msxsl:script implements-prefix="msfunction" language="javascript">
<![CDATA[
function clock(){
var time = new Date();
var year = time.getFullYear();
var month = time.getMonth() + 1;
var day = time.getDate();
var hours = time.getHours();
var min = time.getMinutes();
var sec = time.getSeconds();
return year + "/" + month + "/" + day + " " + hours + ":" + min + ":" + sec ;
}
]]>
</msxsl:script>
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
</head>
<body>
<ul>
<li>Transfer executed at:<xsl:value-of select="msfunction:clock()"/></li>
<!--Status Start-->
<li><b>Status:</b>
<xsl:choose>
<xsl:when test="//Successful/*">
<xsl:choose>
<xsl:when test="//Unsuccessful/*">
Partially Successful
</xsl:when>
<xsl:otherwise>
Successful
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="//Unsuccessful/*">
<xsl:choose>
<xsl:when test="//Successful/*">
Partially Successful
</xsl:when>
<xsl:otherwise>
Unsuccessful
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</li>
<!--Status End-->
<!--Successful Info Start-->
<xsl:if test="//Successful/*">
<li><b>Successful:</b></li>
<ul>
<xsl:for-each select="//Successful/*">
<li><xsl:value-of select="."/> new records inserted into <xsl:value-of select="name()"/> Table</li>
</xsl:for-each>
</ul>
</xsl:if>
<!--Successful Info End-->
<!--Unuccessful Info Start-->
<xsl:if test="//Unsuccessful/*">
<li><b>Unsuccessful:</b></li>
<ul>
<li>The following models could not be transferred:</li>
<table border="1">
<tr>
<td class="col1">Model ID</td>
<td class="col2">Model Name</td>
<td class="col3">Explanation</td>
</tr>
<xsl:for-each select="//Unsuccessful/Job_Competency/Item">
<tr>
<td class="col1"><xsl:value-of select="@Name"/></td>
<td class="col2"><xsl:value-of select="@Name"/></td>
<td class="col3"><xsl:value-of select="@ErrorMsg"/></td>
</tr>
</xsl:for-each>
</table>
</ul>
</xsl:if>
<!--Unsuccessful Info End-->
</ul>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Html
Transfer executed at:2008/11/12 13:45:32
Status: Partially Successful
Successful:
3 new records inserted into Job_Competency Table
Unsuccessful:
The following models could not be transferred:Model ID Model Name Explanation
a a not exist
b b error