i have xml file such as following.
<?xml-stylesheet type='text/xsl' href='AdditionalLogInfo.xsl'?>
<Logs>
<Log TestName="Ew开发者_如何学运维ireDepositTests" Date="Oct 3 11">
<Item>
<Message>Name: blabla</Message>
</Item>
<Item>
<Message>Test Status: Failed</Message>
</Item>
<Item>
<Message>
</Message>
</Item>
<Item>
<Message>[[Logs]]</Message>
</Item>
<Item>
<Message>[ccpayment]</Message>
</Item>
<Item>
<Exception>blabla couldn't be found in the database</Exception>
</Item>
<Item>
<Message>
</Message>
</Item>
<Item>
<Message>[logging]</Message>
</Item>
<Item>
<Exception>couldn't be found in the database</Exception>
</Item>
</Log>
</Logs>
The problem i'm got stuck into is writing an xslt file so that I could view good-looking html page with red lines if there is Exception node in Logs/Log/Item and green lines if there is Message node instead.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<ul>
<xsl:apply-templates select="//Item/*[normalize-space(.)]"/>
</ul>
</body>
</html>
</xsl:template>
<xsl:template match="Message">
<li style="color:green" xmlns="http://www.w3.org/1999/xhtml">
<xsl:value-of select="."/>
</li>
</xsl:template>
<xsl:template match="Exception">
<li style="color:red" xmlns="http://www.w3.org/1999/xhtml">
<xsl:value-of select="."/>
</li>
</xsl:template>
</xsl:stylesheet>
Output:
精彩评论