No XSL transformation of a maximo response

594 views Asked by At

This is my response message:

<?xml version="1.0" encoding="UTF-16"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
    <QueryMXCPISResponse baseLanguage="EN"
        creationDateTime="2014-11-25T11:56:09+01:00"
        maximoVersion="7 5 20130829-1209 V7510--1"
        messageID="1416912970550686680" rsCount="3" rsStart="0"
        rsTotal="3" transLanguage="EN"
        xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <MXCPISSet>
            <CPIS>
                <AK>D</AK>
                <CPISID>630124</CPISID>
                <ORGID>01</ORGID>
                <S1>0</S1>
                <S2>0</S2>
                <S3>0</S3>
                <S4>0</S4>
                <S5>0</S5>
                <S6>1</S6>
                <SHIFT>3</SHIFT>
                <SHIFTDATE>2014-09-30T00:00:00+02:00</SHIFTDATE>
                <SITEID>0030</SITEID>
                <STATUS>NEW</STATUS>
                <TEAM>C</TEAM>
                <WP>LC11</WP>
                <ASSET>
                    <ASSETNUM>LC11</ASSETNUM>
                    <LOCATION>FACILITY-1</LOCATION>
                    <SITEID>0030</SITEID>
                </ASSET>
            </CPIS>
            <CPIS>
                <AK>D</AK>
                <CPISID>630121</CPISID>
                <ORGID>01</ORGID>
                <S1>0</S1>
                <S2>0</S2>
                <S3>1</S3>
                <S4>0</S4>
                <S5>0</S5>
                <S6>1</S6>
                <SHIFT>1</SHIFT>
                <SHIFTDATE>2014-09-30T00:00:00+02:00</SHIFTDATE>
                <SITEID>0030</SITEID>
                <STATUS>CHECKED</STATUS>
                <TEAM>B</TEAM>
                <WP>LC11</WP>
                <ASSET>
                    <ASSETNUM>LC11</ASSETNUM>
                    <LOCATION>FACILITY-1</LOCATION>
                    <SITEID>0030</SITEID>
                </ASSET>
            </CPIS>
            <CPIS>
                <AK>D</AK>
                <CPISID>630122</CPISID>
                <ORGID>01</ORGID>
                <S1>1</S1>
                <S2>1</S2>
                <S3>0</S3>
                <S4>0</S4>
                <S5>0</S5>
                <S6>1</S6>
                <SHIFT>2</SHIFT>
                <SHIFTDATE>2014-09-30T00:00:00+02:00</SHIFTDATE>
                <SITEID>0030</SITEID>
                <STATUS>APPLIED</STATUS>
                <TEAM>B</TEAM>
                <WP>LC11</WP>
                <ASSET>
                    <ASSETNUM>LC11</ASSETNUM>
                    <LOCATION>FACILITY-1</LOCATION>
                    <SITEID>0030</SITEID>
                </ASSET>
            </CPIS>
        </MXCPISSet>
    </QueryMXCPISResponse>
</soapenv:Body>

And this my xsl:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="MXCPISSet">
 <html>
  <body>

   <table>
    <tbody>
     <tr>
      <th>WP</th>
      <th>Site</th>
      <th>Shift</th>
     </tr>

     <xsl:for-each select="CPIS">
     <tr>
      <td><xsl:value-of select="WP"/></td>
      <td><xsl:value-of select="ASSET/SITEID"/></td>
      <td><xsl:value-of select="SHIFT"/></td>
     </tr>
     </xsl:for-each>

    </tbody>
   </table>


  </body>
 </html>
 </xsl:template>

</xsl:stylesheet>

This is the result:

D 630124 01 0 0 0 0 0 1 3 2014-09-30T00:00:00+02:00 0030 NEW C LC11 LC11 FACILITY-1 0030 D 630121 01 0 0 1 0 0 1 1 2014-09-30T00:00:00+02:00 0030 CHECKED B LC11 LC11 FACILITY-1 0030 D 630122 01 1 1 0 0 0 1 2 2014-09-30T00:00:00+02:00 0030 APPLIED B LC11 LC11 FACILITY-1 0030 

If I delete xmlns="http://www.ibm.com/maximo" from response message i get the correct output

WP      Site    Shift
LC11    0030    3
LC11    0030    1
LC11    0030    2

What is wrong in my XSL file that I don't get the HTML output?

1

There are 1 answers

0
StuartLC On BEST ANSWER

The elements QueryMXCPISResponse, MXCPISSet, etc are in the namespace xmlns="http://www.ibm.com/maximo". Without the namespace, the processor doesn't match any elements, and instead of applying your stylesheet, the default processing rules are applied. You'll need to accommodate this namespace in your template, as follows (note the xmlns and alias, m for maximo):

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0"
                xmlns:m="http://www.ibm.com/maximo"
                xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                exclude-result-prefixes="soapenv m">

  <xsl:output method="html"/>

  <xsl:template match="/" >
    <xsl:apply-templates select="m:QueryMXCPISResponse/m:MXCPISSet" />
  </xsl:template>

  <xsl:template match="m:MXCPISSet">
    <html>
      <body>
        <table>
          <tbody>
            <tr>
              <th>WP</th>
              <th>Site</th>
              <th>Shift</th>
            </tr>
            <xsl:for-each select="m:CPIS">
            ... etc.

Other info:

  • Unless you are just transforming the payload in the SOAP body, you potentially need to do the same for the SOAP header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  • If the target is Html, you should also set <xsl:output method="html"/> in the stylesheet.
  • You can potentially DRY up your templates with further apply-templates, in preference to xsl:for-each