2013-11-03 28 views
0

我創建了一個XML文件,併成功通過xsd模式驗證它,然後創建了一個xslt文件,將xml文件中的數據轉換爲表格 ,但每次嘗試將其打開到瀏覽器中時,數據顯示在不一樣的線對錶,我敢肯定,我的代碼是正確的,我不知道爲什麼它不工作,這裏是3個文件: https://www.dropbox.com/sh/gggkh4wg94simrl/2GbiHAGkVFXML操作

XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<?xml-stylesheet type="text/xsl" href="XSLT_XMLToHTML.xml"?> 
<Services> 
    <Service WsdlUrl="http://venus.eas.asu.edu/WSRepository/Services/BasicThreeSvc/Service.svc" TryItUrl=""> 
    <Name>ABasic Three in SVC</Name> 
    <Provider>http://venus.eas.asu.edu</Provider> 
    <Category>SVC</Category> 
    <Operations> 
     <Operation> 
     <Name>HelloWorld</Name> 
     <MsgIn>IService_HelloWorld_InputMessage</MsgIn> 
     <MsgOut>Service_HelloWorld_OutputMessage</MsgOut> 
     </Operation> 
     <Operation> 
     <Name>PiValue</Name> 
     <MsgIn>IService_PiValue_InputMessage</MsgIn> 
     <MsgOut>IService_PiValue_OutputMessage</MsgOut> 
     </Operation> 
<Operation> 
     <Name>absValue</Name> 
     <MsgIn>IService_absValue_InputMessage</MsgIn> 
     <MsgOut>IService_absValue_OutputMessage</MsgOut> 
     </Operation>  
    </Operations> 
    </Service> 

    <Service WsdlUrl="http://venus.eas.asu.edu/WSRepository/Services/EncryptionWcf/Service.svc?wsdl"> 
    <Name>Crypto service in SVC</Name> 
    <Provider>http://venus.eas.asu.edu/</Provider> 
    <Category>SVC</Category> 
    <Operations> 
     <Operation> 
     <Name>Encrypt</Name> 
     <MsgIn>IService_Encrypt_InputMessage</MsgIn> 
     <MsgOut>IService_Encrypt_OutputMessage</MsgOut> 
     </Operation> 
     <Operation> 
     <Name>Decrypt</Name> 
     <MsgIn>IService_Decrypt_InputMessage</MsgIn> 
     <MsgOut>IService_Decrypt_OutputMessage</MsgOut> 
     </Operation> 
    </Operations> 
    </Service> 

    <Service WsdlUrl="http://venus.eas.asu.edu/WSRepository/Services/WFImage/WFService/Service1.xamlx?wsdl"> 
    <Name>Image verifier in workflow</Name> 
    <Provider>http://venus.eas.asu.edu/</Provider> 
    <Category>xamlx</Category> 
    <Operations> 
     <Operation> 
     <Name>GetImage</Name> 
     <MsgIn>IImage_GetImage_InputMessage</MsgIn> 
     <MsgOut>IImage_GetImage_OutputMessage</MsgOut> 
     </Operation> 
     <Operation> 
     <Name>IImage_GetImage_InputMessage</Name> 
     <MsgIn></MsgIn> 
     <MsgOut></MsgOut> 
     </Operation> 
     <Operation> 
     <Name>IImage_GetImage_OutputMessage</Name> 
     <MsgIn></MsgIn> 
     <MsgOut></MsgOut> 
     </Operation>  
     <Operation> 
     <Name>Reboot</Name> 
     <MsgIn>IReboot_Reboot_InputMessage</MsgIn> 
     <MsgOut>IReboot_Reboot_OutputMessage</MsgOut> 
     </Operation> 
     </Operations> 
    </Service> 
    <Service WsdlUrl="http://venus.eas.asu.edu/WSRepository/Services/Encryption/Service.asmx"> 
    <Name>Service</Name> 
    <Provider>http://venus.eas.asu.edu</Provider> 
    <Category>asmx</Category> 
    <Operations> 
     <Operation> 
     <Name>Encrypt</Name> 
     <MsgIn>string</MsgIn> 
     <MsgOut>string</MsgOut> 
     </Operation> 
     <Operation> 
     <Name>Decrypt</Name> 
     <MsgIn>string</MsgIn> 
     <MsgOut>string</MsgOut> 
     </Operation> 
    </Operations> 
    </Service> 

    <Service WsdlUrl="http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl" > 
    <Name>CalculatorServiceServlet</Name> 
    <Provider>http://graphical.weather.gov/</Provider> 
    <Category>PHP</Category> 
    <Operations> 
     <Operation> 
     <Name>NDFDgen</Name> 
     <MsgIn>URL</MsgIn> 
     <MsgOut>URL</MsgOut> 
     </Operation> 
     <Operation> 
     <Name>LatLonListSubgrid</Name> 
     <MsgIn>URL</MsgIn> 
     <MsgOut>URL</MsgOut> 
     </Operation> 
     <Operation> 
     <Name>LatLonListSubgrid</Name> 
     <MsgIn>URL</MsgIn> 
     <MsgOut>URL</MsgOut> 
     </Operation> 
     <Operation> 
     <Name>LatLonListLine</Name> 
     <MsgIn>URL</MsgIn> 
     <MsgOut>URL</MsgOut> 
     </Operation>  
    </Operations> 
    </Service> 

<Service WsdlUrl="http://www.ebi.ac.uk/webservices/whatizit/ws?wsdl" > 
    <Name>pipelineName</Name> 
    <Provider>http://www.ebi.ac.uk/</Provider> 
    <Category>JAVA</Category> 
    <Operations> 
     <Operation> 
     <Name>contact</Name> 
     <MsgIn>contact</MsgIn> 
     <MsgOut>contactResponse</MsgOut> 
     </Operation> 
     <Operation> 
     <Name>getPipelinesStatus</Name> 
     <MsgIn>getPipelinesStatus</MsgIn> 
     <MsgOut>getPipelinesStatusResponse</MsgOut> 
     </Operation> 
     <Operation> 
     <Name>queryPmid</Name> 
     <MsgIn>queryPmid</MsgIn> 
     <MsgOut>WhatizitException</MsgOut> 
     </Operation>   
    </Operations> 
    </Service> 

</Services> 

XSL文件:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output omit-xml-declaration="yes" indent="yes" /> 
    <xsl:template match="node()|@*" /> 
    <xsl:template match="/Services"> 
     <html> 
     <head> 
      <title>XSLT example</title> 
     </head> 
     <body> 
      <xsl:apply-templates /> 
     </body> 
     </html> 
    </xsl:template> 
    <xsl:template match="Service"> 
     <xsl:apply-templates /> 
    </xsl:template> 
    <xsl:template match="Operations"> 
     <table> 
     <thead> 
      <tr> 
       <td>Name</td> 
       <td>Description</td> 
       <td>Type</td> 
      </tr> 
     </thead> 
     <tbody> 
      <xsl:apply-templates /> 
     </tbody> 
     </table> 
    </xsl:template> 
    <xsl:template match="Opertaion"> 
     <!-- [sic] --> 
     <xsl:variable name="service" select="ancestor::Service" /> 
     <tr> 
     <td> 
      <xsl:value-of select="$service/Name" /> 
     </td> 
     <td> 
      <xsl:value-of select="Name" /> 
     </td> 
     <td> 
      <xsl:value-of select="$service/Category" /> 
     </td> 
     </tr> 
    </xsl:template> 
</xsl:transform> 

回答

2

也許這是你的問題一個錯字,但「原文」暗示沒有,因此,問題可能出在這條線

<xsl:template match="Opertaion"> <!-- [sic] --> 

有源XML沒有「Opertaion」元素,只有一個「操作」元素。如果您更改模板以匹配「操作」而不是「Opertaion」,它應該按預期工作。

唯一的困惑是你說「數據顯示在同一行而不是表格中」。通常情況下,這是有道理的,因爲XSLT具有內置模板的概念,在XSLT文檔中指定的節點找不到匹配時使用。內置的模板會爲文本節點輸出文本,但其他節點只是繼續處理其子節點。這可以解釋爲什麼你有一行文本。

但是,你有沒有這個線在你的XSLT

​​

這會在這種情況下匹配「運行」,在這一點上,從而停止處理,這意味着你不應該真正得到任何文本輸出。當然,只要將模板匹配從「Opertaion」更正爲「Operation」,這不會成爲問題。

+0

問題解決了,最後一件事,我無法在瀏覽器中看到邊框,它應該沒有它們? – user1863359

+2

您尚未在輸出的HTML中指定任何關於邊框的內容。如果您將其更改爲輸出'

'您應該看到一些例子,儘管它看起來不太漂亮。這更多的是HTML(或最好是CSS)問題,但與XSLT無關。 –

+0

@TimC,OP直接從[這個答案](http://stackoverflow.com/a/19713250/4525)發佈了XSLT。在這個問題中,示例XML被拼寫錯誤,因此是「sic」。 – harpo