我很快就会成为xsl noob。我有一个报告,当有多个节点时效果很好但是当XML包含单个节点时,它不会显示值。单个节点我指的是报告中1行的1个条目。这是一个例子:
<?xml version="1.0"?>
<Objects>
<Object>
<Property Name="UserName">Will.Bean</Property>
<Property Name="IP_Address">99.99.99.99</Property>
<Property Name="FailureReason">%%2313</Property>
<Property Name="WorkstationName">OKC-CL6</Property>
<Property Name="SubStatus">Bad Password.</Property>
<Property Name="Status">Unknown user name or bad password.</Property>
<Property Name="DomainName">AcmeOrg</Property>
<Property Name="Date">5/27/2017 5:16:48 AM</Property>
</Object>
</Objects>
我用来显示这个的XSL(为简洁而删除了一些样式),并且使用&gt;下面是1个条目。谢谢你的期待。
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Objects/Object">
<html>
<head>
<script src="https://acme.com/sp/SiteAssets/jquery.js"></script>
<script src="https://acme.com/sp/SiteAssets/tablesorter/jquery.tablesorter.min.js"></script>
<style type="text/css">
table.sorttable {
font-family: verdana,arial,sans-serif;
}
</style>
<script type="text/javascript">
$(document).ready(defaultSorter);
function defaultSorter() {
$("#lockouts").tablesorter();
}
</script>
</head>
<body>
<table id="lockouts" class="sorttable">
<thead>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<th>Date</th>
<th>Domain</th>
<th>User</th>
<th>IP_Address</th>
<th>Status</th>
<th>SubStatus</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="Property"/>
</tbody>
<tfoot>
<tr><td>Updated every 30 minutes</td></tr>
</tfoot>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="Property">
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td><xsl:value-of select="Property[@Name='Date']"/></td>
<td><xsl:value-of select="Property[@Name='Domain']"/></td>
<td><xsl:value-of select="Property[@Name='UserName']"/></td>
<td><xsl:value-of select="Property[@Name='IP_Address']"/></td>
<td><xsl:value-of select="Property[@Name='Status']"/></td>
<td><xsl:value-of select="Property[@Name='SubStatus']"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>