Quantcast
Channel: SCN : All Content - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 7030

Matching a Field and Adding an Attribute using XSLT

$
0
0

Hi Experts,

 

My build requires the use of a standard XSD imported as an external definition. This XSD is used for multiple inbound and outbound interfaces.

Now, I am not allowed to edit the XSD. However, I need to add the attribute "xsi:type" to a specific field<ReportParameter> using XSLT.

 

If my input XML looks like this:

 

 

<?xml version="1.0" encoding="utf-8"?>

<Message xmlns:ase="urn:reportheader:one" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance>

<Header>

     <MessageID>DummyID</MessageID>

     <MessageDate>2015-02-12</MessageDate>

</Header>

<Transaction>

     <MainTransaction transactionID="12765FFH">

          <ReportName>My Report</ReportName>

          <ReportNumber>17624</ReportNumber>

          <ReportParameter>

               <Parameter1>Dummy Parameter</Parameter1>

               <Parameter2>Dummy Parameter2</Parameter2>

               <Parameter3>Dummy Parameter3</Parameter3>

          </ReportParameter>

          <ReportDescription>

               <RHeader>Report Header</RHeader>

               <RDescription>Description of report submitted</RDescription>

          </ReportDescription>

     </MainTransaction>

</Transaction>

</Message>

 

The output xml should look like this:

 

<?xml version="1.0" encoding="utf-8"?>

<Message xmlns:ase="urn:reportheader:one" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance>

<Header>

     <MessageID>DummyID</MessageID>

     <MessageDate>2015-02-12</MessageDate>

</Header>

<Transaction>

     <MainTransaction transactionID="12765FFH">

          <ReportName>My Report</ReportName>

          <ReportNumber>17624</ReportNumber>

          <ReportParameterxsi:type="NewEntryReport">

               <Parameter1>Dummy Parameter</Parameter1>

               <Parameter2>Dummy Parameter2</Parameter2>

               <Parameter3>Dummy Parameter3</Parameter3>

          </ReportParameter>

          <ReportDescription>

               <RHeader>Report Header</RHeader>

               <RDescription>Description of report submitted</RDescription>

          </ReportDescription>

     </MainTransaction>

</Transaction>

</Message>

 

How can I search for <ReportParameter> and add the attribute "xsi:type" with value "NewEntryReport"?

I've tried matching the field name like this: <xsl:template match="ReportParameter">

     but it doesn't work.

When I tried 'match="\"', I ended up deleting everything except for the "ReportParameter" segment.

I've also tried using "for-each", but I ended up creating a new copy of the "ReportParameter" segment.

 

Please help.


Viewing all articles
Browse latest Browse all 7030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>