0

我创建了一个 XML 文件并成功地使用 xsd 模式对其进行了验证,然后创建了一个 xslt 文件以将 xml 文件中的数据转换为表格,但是每次尝试将其打开到浏览器中时,数据都显示在相同的行不在桌子上,我很确定我的代码是正确的,我不知道为什么它不起作用,这是 3 个文件: https ://www.dropbox.com/sh/gggkh4wg94simrl/2GbiHAGkVF

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>
4

1 回答 1

2

也许这是您的问题中的错字,但“原文”表明不是,因此问题可能出在这一行

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

源 XML 中没有“Operation”元素,只有一个“Operation”元素。如果您更改模板以匹配“操作”而不是“操作”,它应该可以按预期工作。

唯一的困惑是您说“数据显示在同一行而不是表格上”。通常这是有道理的,因为 XSLT 具有内置模板的概念,在无法找到 XSLT 文档中指定的节点的匹配项时使用这些模板。内置模板将为找到它们的文本节点输出文本,但对于其他节点,只需继续处理其子节点。这可以解释为什么你只有一行文字。

但是,您的 XSLT 中确实有这一行

<xsl:template match="node()|@*"/>

在这种情况下,这将匹配“操作”,因此此时停止处理,这意味着您实际上不应获得任何文本输出。当然,只要您将模板匹配从“操作”更正为“操作”,这将不是问题。

于 2013-11-03T11:28:34.920 回答