2013-10-14 2 views
0

XSLT에 대한 경험이 없습니다. 나는 W3C에서 하나를 포함하여 몇 가지 온라인 튜토리얼을 시도했지만 성공하지는 못했다. Visual Studio Code Metrics 명령 줄 도구로 만든 XML에서 HTML 페이지를 생성하려고합니다.XSLT 지원?

<Module Name="TestVS10XML.dll" AssemblyVersion="1.0.0.0" FileVersion="1.0.0.0"> 
    <Metrics> 
    <Metric Name="MaintainabilityIndex" Value="97" /> 
    <Metric Name="CyclomaticComplexity" Value="10" /> 
    <Metric Name="ClassCoupling" Value="8" /> 
    <Metric Name="DepthOfInheritance" Value="5" /> 
    <Metric Name="LinesOfCode" Value="4" /> 
    </Metrics> 

하지 아래에있는 모든 네임 스페이스 정보 : 만 보고서가 최상위 메트릭을 포함 할

<?xml version="1.0" encoding="utf-8"?> 
<CodeMetricsReport Version="10.0"> 
<Targets> 
<Target Name="C:\Users\rs02130\Documents\Visual Studio 2010\Projects\TestVS10XML\TestVS10XML\Bin\Debug\TestVS10XML.dll"> 
    <Modules> 
     <Module Name="TestVS10XML.dll" AssemblyVersion="1.0.0.0" FileVersion="1.0.0.0"> 
      <Metrics> 
      <Metric Name="MaintainabilityIndex" Value="97" /> 
      <Metric Name="CyclomaticComplexity" Value="10" /> 
      <Metric Name="ClassCoupling" Value="8" /> 
      <Metric Name="DepthOfInheritance" Value="5" /> 
      <Metric Name="LinesOfCode" Value="4" /> 
      </Metrics> 
      <Namespaces> 
      <Namespace Name="TestVS10XML"> 
       <Metrics> 
       <Metric Name="MaintainabilityIndex" Value="97" /> 
       <Metric Name="CyclomaticComplexity" Value="10" /> 
       <Metric Name="ClassCoupling" Value="8" /> 
       <Metric Name="DepthOfInheritance" Value="5" /> 
       <Metric Name="LinesOfCode" Value="4" /> 
       </Metrics> 
       <Types> 
       <Type Name="_Default"> 
        <Metrics> 
        <Metric Name="MaintainabilityIndex" Value="91" /> 
        <Metric Name="CyclomaticComplexity" Value="2" /> 
        <Metric Name="ClassCoupling" Value="5" /> 
        <Metric Name="DepthOfInheritance" Value="4" /> 
        <Metric Name="LinesOfCode" Value="2" /> 
        </Metrics> 
        <Members> 
        <Member Name="Page_Load(object, EventArgs) : void" File="C:\Users\rs02130\Documents\Visual Studio 2010\Projects\TestVS10XML\TestVS10XML\Default.aspx.cs" Line="14"> 
         <Metrics> 
         <Metric Name="MaintainabilityIndex" Value="90" /> 
         <Metric Name="CyclomaticComplexity" Value="1" /> 
         <Metric Name="ClassCoupling" Value="4" /> 
         <Metric Name="LinesOfCode" Value="1" /> 
         </Metrics> 
        </Member> 
        <Member Name="_Default()"> 
         <Metrics> 
         <Metric Name="MaintainabilityIndex" Value="100" /> 
         <Metric Name="CyclomaticComplexity" Value="1" /> 
         <Metric Name="ClassCoupling" Value="1" /> 
         <Metric Name="LinesOfCode" Value="1" /> 
         </Metrics> 
        </Member> 
        </Members> 
       </Type> 
       <Type Name="SiteMaster"> 
        <Metrics> 
        <Metric Name="MaintainabilityIndex" Value="100" /> 
        <Metric Name="CyclomaticComplexity" Value="2" /> 
        <Metric Name="ClassCoupling" Value="3" /> 
        <Metric Name="DepthOfInheritance" Value="5" /> 
        <Metric Name="LinesOfCode" Value="1" /> 
        </Metrics> 
        <Members> 
        <Member Name="Page_Load(object, EventArgs) : void" File="C:\Users\rs02130\Documents\Visual Studio 2010\Projects\TestVS10XML\TestVS10XML\Site.Master.cs" Line="13"> 
         <Metrics> 
         <Metric Name="MaintainabilityIndex" Value="100" /> 
         <Metric Name="CyclomaticComplexity" Value="1" /> 
         <Metric Name="ClassCoupling" Value="1" /> 
         <Metric Name="LinesOfCode" Value="0" /> 
         </Metrics> 
        </Member> 
        <Member Name="SiteMaster()"> 
         <Metrics> 
         <Metric Name="MaintainabilityIndex" Value="100" /> 
         <Metric Name="CyclomaticComplexity" Value="1" /> 
         <Metric Name="ClassCoupling" Value="1" /> 
         <Metric Name="LinesOfCode" Value="1" /> 
         </Metrics> 
        </Member> 
        </Members> 
       </Type> 
       <Type Name="Global"> 
        <Metrics> 
        <Metric Name="MaintainabilityIndex" Value="100" /> 
        <Metric Name="CyclomaticComplexity" Value="6" /> 
        <Metric Name="ClassCoupling" Value="2" /> 
        <Metric Name="DepthOfInheritance" Value="2" /> 
        <Metric Name="LinesOfCode" Value="1" /> 
        </Metrics> 
        <Members> 
        <Member Name="Application_Start(object, EventArgs) : void" File="C:\Users\rs02130\Documents\Visual Studio 2010\Projects\TestVS10XML\TestVS10XML\Global.asax.cs" Line="14"> 
         <Metrics> 
         <Metric Name="MaintainabilityIndex" Value="100" /> 
         <Metric Name="CyclomaticComplexity" Value="1" /> 
         <Metric Name="ClassCoupling" Value="1" /> 
         <Metric Name="LinesOfCode" Value="0" /> 
         </Metrics> 
        </Member> 
        <Member Name="Application_End(object, EventArgs) : void" File="C:\Users\rs02130\Documents\Visual Studio 2010\Projects\TestVS10XML\TestVS10XML\Global.asax.cs" Line="20"> 
         <Metrics> 
         <Metric Name="MaintainabilityIndex" Value="100" /> 
         <Metric Name="CyclomaticComplexity" Value="1" /> 
         <Metric Name="ClassCoupling" Value="1" /> 
         <Metric Name="LinesOfCode" Value="0" /> 
         </Metrics> 
        </Member> 
        <Member Name="Application_Error(object, EventArgs) : void" File="C:\Users\rs02130\Documents\Visual Studio 2010\Projects\TestVS10XML\TestVS10XML\Global.asax.cs" Line="26"> 
         <Metrics> 
         <Metric Name="MaintainabilityIndex" Value="100" /> 
         <Metric Name="CyclomaticComplexity" Value="1" /> 
         <Metric Name="ClassCoupling" Value="1" /> 
         <Metric Name="LinesOfCode" Value="0" /> 
         </Metrics> 
        </Member> 
        <Member Name="Session_Start(object, EventArgs) : void" File="C:\Users\rs02130\Documents\Visual Studio 2010\Projects\TestVS10XML\TestVS10XML\Global.asax.cs" Line="32"> 
         <Metrics> 
         <Metric Name="MaintainabilityIndex" Value="100" /> 
         <Metric Name="CyclomaticComplexity" Value="1" /> 
         <Metric Name="ClassCoupling" Value="1" /> 
         <Metric Name="LinesOfCode" Value="0" /> 
         </Metrics> 
        </Member> 
        <Member Name="Session_End(object, EventArgs) : void" File="C:\Users\rs02130\Documents\Visual Studio 2010\Projects\TestVS10XML\TestVS10XML\Global.asax.cs" Line="38"> 
         <Metrics> 
         <Metric Name="MaintainabilityIndex" Value="100" /> 
         <Metric Name="CyclomaticComplexity" Value="1" /> 
         <Metric Name="ClassCoupling" Value="1" /> 
         <Metric Name="LinesOfCode" Value="0" /> 
         </Metrics> 
        </Member> 
        <Member Name="Global()"> 
         <Metrics> 
         <Metric Name="MaintainabilityIndex" Value="100" /> 
         <Metric Name="CyclomaticComplexity" Value="1" /> 
         <Metric Name="ClassCoupling" Value="1" /> 
         <Metric Name="LinesOfCode" Value="1" /> 
         </Metrics> 
        </Member> 
        </Members> 
       </Type> 
       </Types> 
      </Namespace> 
      </Namespaces> 
     </Module> 
     </Modules> 
    </Target> 
    </Targets> 
</CodeMetricsReport> 

: 같은 XML은 보인다. 나는이 XSLT (모듈 이름도 포함하고 있지 않다.)를 생각해 냈지만, 나는 그것을 실행할 때 열 머리글 만 얻었고 테이블에는 데이터가 없었다. 내가 W3C에서 온라인 자습서가 믿지 않는

<?xml version="1.0" encoding="utf-8"?> 
<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="/"> 
    <table width="100%" align="center" cellpadding="0" cellspacing="0" border="1" 
     style="font-family:verdana;font-size:10pt;border:1"> 
<tr> 
    <td width="20%" align="left" > 
    Maintainability Index 
    </td> 
    <td width="20%" align="left"> 
    Cyclomatic Complexity 
    </td> 
    <td width="20%" align="left"> 
    Class Coupling 
    </td> 
    <td width="20%" align="left"> 
    Depth Of Inheritance 
    </td> 
    <td width="20%" align="left"> 
    Lines Of Code 
    </td> 
</tr> 
    </table> 
<xsl:for-each select="Targets/Modules/Metrics"> 
<table width="100%" align="center" cellpadding="0" cellspacing="0" border="1" 
    style="font-family:verdana;font-size:10pt;border:1"> 
    <tr > 
     <td width="20%" align="left" > 
     <xsl:value-of select="MaintainabilityIndex"/> 
    </td> 
    <td width="20%" align="left" > 
      <xsl:value-of select="CyclomaticComplexity"/> 
    </td> 
    <td width="20%" align="left" > 
     <xsl:value-of select="ClassCoupling"/> 
    </td> 
    <td width="20%" align="left" > 
     <xsl:value-of select="DepthOfInheritance"/> 
    </td> 
    <td width="20%" align="left" > 
     <xsl:value-of select="LinesOfCode"/> 
    </td> 
    </tr> 
</table> 
</xsl:for-each> 
</xsl:template> 
</xsl:stylesheet> 
+1

: 어떤 도움을 크게

XSLT ... 감사합니다. w3schools를 언급하는 경우 W3C와 관련이 없습니다. 일반적으로, 나는 이런 종류의 튜토리얼로부터 XSLT를 배우려고 시도하는 것이 좋은 접근 방법이 아니라고 생각한다. 개념을 제대로 설명하는 훌륭한 책을 읽으십시오. –

답변

0
<!-- you don't use the msxsl namespace, you could drop its declaration --> 
<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="CodeMetricsReport"> 
    <!-- you really ought to do all this styling in CSS --> 
    <table width="100%" align="center" cellpadding="0" cellspacing="0" border="1" 
     style="font-family:verdana;font-size:10pt;border:1"> 
     <tr> 
     <td width="20%" align="left">Maintainability Index</td> 
     <td width="20%" align="left">Cyclomatic Complexity</td> 
     <td width="20%" align="left">Class Coupling</td> 
     <td width="20%" align="left">Depth Of Inheritance</td> 
     <td width="20%" align="left">Lines Of Code</td> 
     </tr> 

     <!-- that's what you forgot --> 
     <xsl:apply-templates select="Targets/Target/Modules/Module/Metrics" /> 
    </table> 
    </xsl:template> 

    <xsl:template match="Metrics"> 
    <tr> 
     <td width="20%" align="left"> 
     <xsl:value-of select="Metric[@Name = 'MaintainabilityIndex']/@Value" /> 
     </td> 
     <td width="20%" align="left"> 
     <xsl:value-of select="Metric[@Name = 'CyclomaticComplexity']/@Value" /> 
     </td> 
     <td width="20%" align="left"> 
     <xsl:value-of select="Metric[@Name = 'ClassCoupling']/@Value" /> 
     </td> 
     <td width="20%" align="left"> 
     <xsl:value-of select="Metric[@Name = 'DepthOfInheritance']/@Value" /> 
     </td> 
     <td width="20%" align="left"> 
     <xsl:value-of select="Metric[@Name = 'LinesOfCode']/@Value" /> 
     </td> 
    </tr> 
    </xsl:template> 
</xsl:stylesheet> 
+0

장기간 사용하기 위해 XSLT를 배우려는 목적이 있다면 여러 권의 좋은 책을 얻었을 것입니다. 이런 종류의 일은 또 다른 일의 일부로 내게 뛰어 들었다. 나는 XML 파일로 끝나서 HTML 페이지로 변환하도록 요청 받았다. 전에 그 일을 해 본 적이 없으니 ... –

+0

도와 줘서 고마워요. @ 마이클 케이. 한가지 더 물어볼 수 있다면. 의 "name"값을 삽입 할 수있는 방법이 있나요? 아니면 필요한 모든 것을 제공 할 테이블의 첫 번째 행으로. 그들이 돌아와서 더 많은 것을 요구하면 (즉, 네임 스페이스) 책 하나 또는 둘을 가져갈 것입니다. 다시 한번 감사드립니다. –

+0

어 ... 나는 마이클 케이가 아니야. 당연히 물어보고 싶니? – Tomalak