XML Manipulation

2019-08-23 06:41发布

i created an XML files and succeeded validating it with an xsd schema , then a created an xslt file to turn the data on the xml file into a table but every time time a tried to open it into a browser , data are displayed in the same line not on a table , i'm pretty sure that my code is correct and i don't know why it doesn't work , here is the 3 files : https://www.dropbox.com/sh/gggkh4wg94simrl/2GbiHAGkVF

XML FIle:

<?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 File:

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

1条回答
Rolldiameter
2楼-- · 2019-08-23 07:08

Maybe this is a typo in your question, but the "sic" suggests not, therefore the issue could be with this line

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

There is no "Opertaion" element in the source XML, only an "Operation" element. If you change template to match "Operation" and not "Opertaion" it should work as expected.

The only confusion is where you say "data are displayed in the same line not on a table". Normally this would make sense, because XSLT has the concept of built-in templates, which are used where it can't find a match for a node specified in the XSLT document. The built-in templates will output text for text nodes where it find them, but for other nodes just continue processing its children. This would explain why you got a line of just text.

However, you do have this line in your XSLT

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

This would match "Operation" in this case, and so stop processing at this point, meaning you should not actually get any text output. Of course, as soon as you correct the template match from "Opertaion" to "Operation", this won't be an issue.

查看更多
登录 后发表回答