我有一个XML文件,想将其转换为HTML表格文件。 这是我的XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<CONTACTS>
<CONTACT>
<FirstName>AfgZohal</FirstName>
<LastName>Zohal Afg</LastName>
<EMAILS/>
</CONTACT>
<CONTACT>
<FirstName>Rangarajkarthik</FirstName>
<LastName>karthik Rangaraj</LastName>
<EMAILS>
<EMail>
<Type>gmail</Type>
<Value>kart2006@gmail.com</Value>
</EMail>
<EMail>
<Type>yahoo</Type>
<Value>karthikrangaraj@yahoo.com</Value>
</EMail>
</EMAILS>
</CONTACT>
<CONTACT>
<FirstName>ReganPaul</FirstName>
<LastName>Paul Michael Regan</LastName>
<URL>http://www.facebook.com/profile.php?id=1660466705</URL>
<EMAILS/>
</CONTACT>
<CONTACT>
<FirstName>keyankarthik</FirstName>
<LastName>karthik keyan</LastName>
<EMAILS>
<EMail>
<Type>yahoo</Type>
<Value>karthycse@yahoo.co.in</Value>
</EMail>
</EMAILS>
</CONTACT>
<CONTACT>
<FirstName>ColomboGiorgia</FirstName>
<LastName>Giorgia Colombo</LastName>
<EMAILS>
<EMail>
<Type>libero</Type>
<Value>giorgiacolombo89@libero.it</Value>
</EMail>
</EMAILS>
</CONTACT>
</CONTACTS>
这是我的XSL文件:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<!-- / forward slash is used to denote a patern that matches
the root node of the XML document -->
<xsl:template match ="/" >
<html>
<head>
<title> ContactMatrix</title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="CONTACTS" >
<table width="400" border="1" >
<tr bgcolor = "#546789" >
<td>FirstName</td>
<td>LastName</td>
<td>Gmail</td>
<td>Yahoo</td>
<td>Libero</td>
<td>URL</td>
</tr>
<xsl:for-each select="CONTACT" >
<tr>
<td> <xsl:value-of select="FirstName"/> </td>
<td> <xsl:value-of select="LastName"/> </td>
<!-- here we use /@ to access the value of an attribute -->
<td> <xsl:value-of select="Type/Value=@gmail.com"/> </td>
<td> <xsl:value-of select="@yahoo.com"/> </td>
<td> <xsl:value-of select="@libero.it"/> </td>
<td> <xsl:value-of select="URL"/> </td>
</tr>
</xsl:for-each>
</table>
</xsl:template >
</xsl:stylesheet >
在我的HTML表格中,gmail、yahoo、libero的值为False。以下是HTML文件中
FirstName:Rangarajkarthik
的示例代码。<tr>
<td>Rangarajkarthik</td><td>karthik Rangaraj</td><td>false</td><td>false</td><td>false</td><td></td>
</tr>
请协助我。