自定义 XSLT 定义能否处理在定义 MBO 时返回对象数组的 SOAP 响应?

发布于 2024-11-24 03:35:32 字数 3310 浏览 2 评论 0原文

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

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>

I seem to have run into a limitation in SUP regarding its ability to handle a SOAP response containing a list of objects and I am wondering if it would be possible to write a custom XSLT to handle this. I am trying to make a call into Jira via the getProjectsNoSchemes method via SOAP. This method returns an array of RemoteProject objects. Ultimately I would like to be able to treat each node as a row in a table, but unfortunately I don't know enough about XSLT to be able to know if this is possible or not. I also don't know if this is even a viable solution in SUP.

A sample of the SOAP response is below:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

西瓜 2024-12-01 03:35:32

是的,这是可能的,而且相对容易做到。

下面是一个 XSLT 示例,它生成一个 HTML 文档,其中每个 元素都有一个表格行。

的每个子元素首先使用标题列的元素名称呈现为表格标题,然后每个 呈现为每个子元素都有行和列:

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

Yes, it's possible, and relatively easy to do so.

Below is an example XSLT that produces an HTML document with a table row for each <multRef> element.

Each child element of <multiRef> is first rendered as a table header using the name of the element for the heading column, and then each <multiRef> is rendered as rows with columns for each of the child elements:

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

When applied to the sample XML provided, it produces the following 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>
素食主义者 2024-12-01 03:35:32

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>

SUP expects the XML in a very specific format so I had to traverse through the multi-refs in the response using the for-each construct:

<?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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文