Ashok.N
Ashok.N

Reputation: 1391

Concatenation of node values based on a condition in XSLT

I have the following xml.

<?xml version="1.0" encoding="UTF-8"?>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP:Body>
      <response:performJobResponse xmlns:response="http://tempuri.org/" SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <whiteboard>
            <PQ>
               <response>
                  <PQIssueHistory>
                     <AWD10SP7_1orhigher>Y</AWD10SP7_1orhigher>
                     <hostAddress>10.193.XXX.78</hostAddress>
                     <hostPort>12955</hostPort>
                     <userID>7X606</userID>
                     <password>Qfgjf@123</password>
                     <issue>
                        <CRDATTIM>2015-07-29-04.27.15.461040</CRDATTIM>
                        <RECORDCD>T</RECORDCD>
                        <CRNODE>01</CRNODE>
                        <ORIGUSERID>DT77214</ORIGUSERID>
                     </issue>
                  </PQIssueHistory>
                  <results>
                     <row>
                        <RECTYP>HISTORY</RECTYP>
                     </row>
                     <row>
                        <date>2015-08-18</date>
                        <time>04:04:58-05:00</time>
                     </row>
                  </results>
               </response>
            </PQ>
         </whiteboard>
         <jobReturn>
            <taskName>TransformNode</taskName>
            <description>TransformNode Succeeded</description>
            <value>0</value>
         </jobReturn>
      </response:performJobResponse>
   </SOAP:Body>
</SOAP:Envelope>

First of all, I need to check whether any <row> has <date> and <time>, if so, I should concatenate the values of <date> and <time> and assign the newly generated value to a new tag <CRDATTIM> </CRDATTIM>.

For example: <CRDATTIM>2015-08-18-04:04:58-05:00</CRDATTIM>

Final resultant xml should be as below:

  <?xml version="1.0" encoding="UTF-8"?>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP:Body>
      <response:performJobResponse xmlns:response="http://tempuri.org/" SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <whiteboard>
            <PQ>
               <response>
                  <PQIssueHistory>
                     <AWD10SP7_1orhigher>Y</AWD10SP7_1orhigher>
                     <hostAddress>10.193.XXX.78</hostAddress>
                     <hostPort>12955</hostPort>
                     <userID>7X606</userID>
                     <password>Qfgjf@123</password>
                     <issue>
                        <CRDATTIM>2015-07-29-04.27.15.461040</CRDATTIM>
                        <RECORDCD>T</RECORDCD>
                        <CRNODE>01</CRNODE>
                        <ORIGUSERID>DT77214</ORIGUSERID>
                     </issue>
                  </PQIssueHistory>
                  <results>
                     <row>
                        <RECTYP>HISTORY</RECTYP>
                     </row>
                     <row>
                        <CRDATTIM>2015-08-18-04:04:58-05:00</CRDATTIM>
                     </row>
                  </results>
               </response>
            </PQ>
         </whiteboard>
         <jobReturn>
            <taskName>TransformNode</taskName>
            <description>TransformNode Succeeded</description>
            <value>0</value>
         </jobReturn>
      </response:performJobResponse>
   </SOAP:Body>
</SOAP:Envelope>

Upvotes: 1

Views: 80

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116982

Having problems in verifying whether the <date> and <time> exist under <row> or not.

Write a template matching the wanted rows:

<xsl:template match="row[date and time]">

and put the processing code in it.

Upvotes: 1

Related Questions