我試圖轉換下列由metric.exe生成的用於我的解決方案中的程序集的XML。而且我不是XSLT的專家,並且努力達到問題底部所示的格式。請幫忙。通過metric.exe生成的XML的XSLT轉換
的XML
<?xml version="1.0" encoding="utf-8"?>
<CodeMetricsReport Version="12.0">
<Targets>
<Target Name="E:\some-imaginary-path\some-imaginary-dll">
<Modules>
<Module Name="some-imaginary-dll" AssemblyVersion="1.0.0.0" FileVersion="1.0.0.0">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="84" />
<Metric Name="CyclomaticComplexity" Value="95" />
<Metric Name="ClassCoupling" Value="109" />
<Metric Name="DepthOfInheritance" Value="4" />
<Metric Name="LinesOfCode" Value="214" />
</Metrics>
<Namespaces>
<Namespace Name="LMS.SomeNamespace">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="89" />
<Metric Name="CyclomaticComplexity" Value="19" />
<Metric Name="ClassCoupling" Value="18" />
<Metric Name="DepthOfInheritance" Value="1" />
<Metric Name="LinesOfCode" Value="29" />
</Metrics>
<Types>
<Type Name="SomeType1">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="100" />
<Metric Name="CyclomaticComplexity" Value="1" />
<Metric Name="ClassCoupling" Value="1" />
<Metric Name="DepthOfInheritance" Value="0" />
<Metric Name="LinesOfCode" Value="0" />
</Metrics>
<Members>
<Member Name="SomeMemberFor1">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="100" />
<Metric Name="CyclomaticComplexity" Value="1" />
<Metric Name="ClassCoupling" Value="1" />
<Metric Name="LinesOfCode" Value="0" />
</Metrics>
</Member>
</Members>
</Type>
<Type Name="SomeType2">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="76" />
<Metric Name="CyclomaticComplexity" Value="3" />
<Metric Name="ClassCoupling" Value="6" />
<Metric Name="DepthOfInheritance" Value="1" />
<Metric Name="LinesOfCode" Value="7" />
</Metrics>
<Members>
<Member Name="SomeMemberFor2" File="e:\some-file.cs" Line="27">
<Metrics>
<Metric Name="MaintainabilityIndex" Value="67" />
<Metric Name="CyclomaticComplexity" Value="2" />
<Metric Name="ClassCoupling" Value="5" />
<Metric Name="LinesOfCode" Value="6" />
</Metrics>
</Member>
</Namespace>
</Namespaces>
</Module>
</Namespace>
</Namespaces>
</Module>
</Modules>
</Target>
</Targets>
</CodeMetricsReport>
的XSLT
到目前爲止使用PowerShell腳本(某些變化工作過部分這樣的PowerShell腳本沒有過錯這裏)轉化時,這會產生什麼
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"
>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<h2>x</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Name Space Name</th>
<th>Type Name</th>
<th>Member Name</th>
<th>MaintainabilityIndex</th>
<th>CyclomaticComplexity</th>
<th>ClassCoupling</th>
<th>DepthOfInheritance</th>
<th>LinesOfCode</th>
</tr>
<xsl:for-each select="CodeMetricsReport/Targets/Target/Modules/Namespaces/Namespace/Metrics">
<tr>
<td><xsl:value-of select="./Metric[@Name = '????']/@Value" /></td>
<td><xsl:value-of select="./Metric[@Name = '????']/@Value" /></td>
<td><xsl:value-of select="./Metric[@Name = '????']/@Value" /></td>
<td><xsl:value-of select="./Metric[@Name = 'MaintainabilityIndex']/@Value" /></td>
<td><xsl:value-of select="./Metric[@Name = 'CyclomaticComplexity']/@Value"/></td>
<td><xsl:value-of select="./Metric[@Name = 'ClassCoupling']/@Value"/></td>
<td><xsl:value-of select="./Metric[@Name = 'DepthOfInheritance']/@Value"/></td>
<td><xsl:value-of select="./Metric[@Name = 'LinesOfCode']/@Value"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我估計的HTML婷achive
<table border="1">
<tr bgcolor="#9acd32">
<th>Name Space Name</th>
<th>Type Name</th>
<th>Member Name</th>
<th>MaintainabilityIndex</th>
<th>CyclomaticComplexity</th>
<th>ClassCoupling</th>
<th>DepthOfInheritance</th>
<th>LinesOfCode</th>
</tr>
<tr>
<td>Name of namespace</td>
<td>Type name</td>
<td>Member name</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
預先感謝作出的任何幫助。
沒有很好地形成你的輸入文檔。你能糾正嗎? –