自定义XSLT定义可以处理定义MBO时返回对象数组的SOAP响应吗?

问题描述:

我似乎遇到了SUP的限制,因为它处理包含对象列表的SOAP响应的能力,我想知道是否可以编写自定义XSLT来处理这个问题。我试图通过SOAP通过getProjectsNoSchemes方法调用Jira。此方法返回RemoteProject对象的数组。最终,我希望能够将每个节点视为表中的一行,但不幸的是,我不知道XSLT是否能够知道这是否可行。我也不知道这是否是SUP的可行解决方案。自定义XSLT定义可以处理定义MBO时返回对象数组的SOAP响应吗?

SOAP响应的样品低于:

<?xml version="1.0" encoding="utf-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<soapenv:Body> 
    <ns1:GetProjectsNoSchemesResponse 
     soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
     xmlns:ns1="http://www.webserviceX.NET"> 
     <GetProjectsNoSchemesReturn 
      soapenc:arrayType="ns2:RemoteProject[2]" xsi:type="soapenc:Array" 
      xmlns:ns2="http://beans.soap.rpc.jira.atlassian.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
      <GetProjectsNoSchemesReturn href="#id0" /> 
      <GetProjectsNoSchemesReturn href="#id1" /> 
     </GetProjectsNoSchemesReturn> 
    </ns1:GetProjectsNoSchemesResponse> 
    <multiRef id="id0" soapenc:root="0" 
     soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
     xsi:type="ns3:RemoteProject" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
     xmlns:ns3="http://beans.soap.rpc.jira.atlassian.com"> 
     <description xsi:type="xsd:string">Mobile Web Project POC 
     </description> 
     <id xsi:type="xsd:string">10034</id> 
     <issueSecurityScheme xsi:type="ns3:RemoteScheme" 
      xsi:nil="true" /> 
     <key xsi:type="xsd:string">XLIPOC</key> 
     <lead xsi:type="xsd:string">benm</lead> 
     <name xsi:type="xsd:string">Redacted Project</name> 
     <notificationScheme xsi:type="ns3:RemoteScheme" 
      xsi:nil="true" /> 
     <permissionScheme xsi:type="ns3:RemotePermissionScheme" 
      xsi:nil="true" /> 
     <projectUrl xsi:type="xsd:string"></projectUrl> 
     <url xsi:type="xsd:string">https://redacted.com/browse/REDACTED</url> 
    </multiRef> 
    <multiRef id="id1" soapenc:root="0" 
     soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
     xsi:type="ns4:RemoteProject" xmlns:ns4="http://beans.soap.rpc.jira.atlassian.com" 
     xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
     <description xsi:type="xsd:string"></description> 
     <id xsi:type="xsd:string">10017</id> 
     <issueSecurityScheme xsi:type="ns4:RemoteScheme" 
      xsi:nil="true" /> 
     <key xsi:type="xsd:string">GIC</key> 
     <lead xsi:type="xsd:string">gregm</lead> 
     <name xsi:type="xsd:string">REDACTED</name> 
     <notificationScheme xsi:type="ns4:RemoteScheme" 
      xsi:nil="true" /> 
     <permissionScheme xsi:type="ns4:RemotePermissionScheme" 
      xsi:nil="true" /> 
     <projectUrl xsi:type="xsd:string"></projectUrl> 
     <url xsi:type="xsd:string">https://redacted.com/browse/REDACTED</url> 
    </multiRef> 
</soapenv:Body> 

+0

生成将每个multiRef元素转换为(HTTML?)行的XSLT并不太困难。你想在每一列的列中想要什么?如果你能提供样本输出,有人可能会提供一个答案让你开始。 –

是的,这是可能的,而且比较容易做到的。

下面是一个示例XSLT,它为每个<multRef>元素生成一个带有表格行的HTML文档。

<multiRef>每个子元素被首先呈现为使用用于标题列中的元素的名称表头,然后将每个<multiRef>呈现为行与列的每个子元素的:

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"> 
     <html> 
      <head></head> 
      <body> 
       <table border="1"> 
        <xsl:apply-templates select="*/*/multiRef[1]" mode="header"/> 
        <xsl:apply-templates select="*/*/multiRef" /> 
       </table> 
      </body> 
     </html> 
    </xsl:template> 

    <xsl:template match="multiRef" mode="header"> 
     <thead> 
      <tr> 
       <xsl:apply-templates mode="header"/> 
      </tr> 
     </thead> 
    </xsl:template> 

    <xsl:template match="multiRef/*" mode="header"> 
     <th> 
      <xsl:value-of select="local-name()"/> 
     </th> 
    </xsl:template> 

    <xsl:template match="multiRef"> 
     <tr> 
      <xsl:apply-templates/> 
     </tr> 
    </xsl:template> 

    <xsl:template match="multiRef/*"> 
     <td> 
      <xsl:apply-templates/> 
     </td> 
    </xsl:template> 
</xsl:stylesheet> 

当施加到所提供的样本XML,它产生以下HTML:

<html> 
    <head> 
    <META http-equiv="Content-Type" content="text/html; charset=UTF-16"> 
    </head> 
    <body> 
     <table border="1"> 
      <thead> 
       <tr> 
        <th>description</th> 
        <th>id</th> 
        <th>issueSecurityScheme</th> 
        <th>key</th> 
        <th>lead</th> 
        <th>name</th> 
        <th>notificationScheme</th> 
        <th>permissionScheme</th> 
        <th>projectUrl</th> 
        <th>url</th> 
       </tr> 
      </thead> 
      <tr> 
       <td>Mobile Web Project POC 
       </td> 
       <td>10034</td> 
       <td></td> 
       <td>XLIPOC</td> 
       <td>benm</td> 
       <td>Redacted Project</td> 
       <td></td> 
       <td></td> 
       <td></td> 
       <td>https://redacted.com/browse/REDACTED</td> 
      </tr> 
      <tr> 
       <td></td> 
       <td>10017</td> 
       <td></td> 
       <td>GIC</td> 
       <td>gregm</td> 
       <td>REDACTED</td> 
       <td></td> 
       <td></td> 
       <td></td> 
       <td>https://redacted.com/browse/REDACTED</td> 
      </tr> 
     </table> 
    </body> 
</html> 
+0

谢谢这真的很有帮助,并让我走上正轨! – janarde

SUP期望的XML在一个非常特定的格式,所以我不得不使用for-each结构,通过在响应中的多参遍历:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="//ns1:getProjectsNoSchemesResponse"> 
    <data> 
     <Record> 
      <Field op_label="id" op_position="1" op_datatype="STRING" op_nullable="true">id</Field> 
      <Field op_label="name" op_position="2" op_datatype="STRING" op_nullable="true">name</Field> 
      <Field op_label="description" op_position="3" op_datatype="STRING" op_nullable="true">description</Field> 
     </Record> 
     <xsl:for-each select="//ns1:getProjectsNoSchemesResponse/getProjectsNoSchemesReturn/href*"> 
      <Record> 
       <Field> 
        <xsl:attribute name="op_label">id</xsl:attribute> 
        <xsl:attribute name="op_position">1</xsl:attribute> 
        <xsl:attribute name="op_datatype">STRING</xsl:attribute> 
        <xsl:attribute name="op_nullable">true</xsl:attribute> 
        <xsl:value-of select="getProjectNoSchemesReturn/id" /> 
       </Field> 
       <Field> 
        <xsl:attribute name="op_label">name</xsl:attribute> 
        <xsl:attribute name="op_position">2</xsl:attribute> 
        <xsl:attribute name="op_datatype">STRING</xsl:attribute> 
        <xsl:attribute name="op_nullable">true</xsl:attribute> 
        <xsl:value-of select="getProjectNoSchemesReturn/name" /> 
       </Field> 
       <Field> 
        <xsl:attribute name="op_label">description</xsl:attribute> 
        <xsl:attribute name="op_position">3</xsl:attribute> 
        <xsl:attribute name="op_datatype">STRING</xsl:attribute> 
        <xsl:attribute name="op_nullable">true</xsl:attribute> 
        <xsl:value-of select="getProjectNoSchemesReturn/name" /> 
       </Field> 
      </Record> 
     </xsl:for-each> 
    </data> 
    </xsl:template> 
</xsl:stylesheet>