XSLT Transformation in REST DC

Use Case:
This blog explains about applying XSLT transformation on a REST Service while creating the Rest DataControl. Here I will be explaining on how the data is getting manipulated and is rendered by the REST DC when XSL is applied on it.

JDeveloper Version used : 12.1.2

Steps:
1. Consider an Scenario where an REST Service API is retuning an XML response as mentioned below

<?xml version = '1.0' encoding = 'UTF-8' standalone = 'yes'?>
<departments>
   <department>
      <deptId>1001</deptId>
      <deptName>HumanResource</deptName>
   </department>
   <department>
      <deptId>2002</deptId>
      <deptName>Finance</deptName>
   </department>
   <department>
      <deptId>3003</deptId>
      <deptName>Research</deptName>
   </department>
   <department>
      <deptId>5005</deptId>
      <deptName>Sales</deptName>
   </department>
</departments>


2. Lets create an XSD structure to contain two more new attributes e.g CUSTOMNAME of type String and UNIQUEID of type integer

<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xsd:element name="departments">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="department" maxOccurs="unbounded">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="deptId" type="xsd:integer"/>
              <xsd:element name="deptName" type="xsd:string"/>
              <xsd:element name="customUniqueId" type="xsd:integer"/>
              <xsd:element name="customName" type="xsd:string"/>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

3. Now we have to create an XSL File to transform data , so that the values can be populated for the new attributes.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:ns2="http://project1/">
    <xsl:template match="departments">
        <departments>
          <xsl:for-each select="department">
              <department>
                  <deptName><xsl:value-of select="deptName"/></deptName>
                  <deptId><xsl:value-of select="deptId"/></deptId>
                  <customName><xsl:value-of select="concat('CUST_',deptName)"/></customName>
                  <customUniqueId><xsl:value-of select="deptId * 2"/></customUniqueId>
              </department>      
          </xsl:for-each> 
        </departments>
    </xsl:template>
</xsl:stylesheet>

4. In Jdeveloper, invoke the WSDC wizard, select the type as REST, in the wizard provide the name for the DC and create the connection.



5. In the Next Step of the wizard, provide the resource path and the method name for the operation



6. In the Method Details Step of the wizard provide the Cutsom XSD and  XSL file for the method as shown below



7.  Click Next and Complete the Wizard, then Expand the DC palette to find the Structure as shown below



8. Drag and Drop the departmentNode onto the page as an ADF table and Run the page


9. Here we can observe the value being populated for the customUniqueId and customName as per the definition given in the XSL file

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Tips and Tricks from Oracle's JDeveloper & ADF QA

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today