Wednesday, February 20, 2013

Migrating the BAM objects across environments with the ANT script – Oracle BAM 11g

Migrating the BAM objects across environments with the ANT script – Oracle BAM 11g

This post explains how to use the ANT script to migrate the Oracle BAM objects across the environments.The script can be run remotely from the client machine or from the server machine.
  • Create a folder BAMConfig and create two sub folders BAMObjects and config inside the BAMConfig folder
  • Copy the BAMICommandConfig.xml from $ORACLE_HOME/bam/config folder of the server to the config folder created in the above step.
  • Add the default user name and the password to the BAMICommandConfig.xml file
           <ICommand_Default_User_Name>weblogic</ICommand_Default_User_Name>
           <ICommand_Default_Password>hiyEbs0vwXPQrKh8yE7z3f7JVNhmLLEe+cR3bansiPc=</ICommand_Default_Password>

         Also verify the ADCServerPort - the BAM Server http listening port and   ADCServerName -  BAM Server host name properties.

Content of the configuration file:

<?xml version="1.0" encoding="UTF-8"?><BAMICommand>
<ADCServerPort>9001</ADCServerPort>
<ADCServerName>BAM Server hostname</ADCServerName>
<ICommand_Default_User_Name>weblogic</ICommand_Default_User_Name>
<ICommand_Default_Password>hiyEbs0vwXPQrKh8yE7z3f7JVNhmLLEe+cR3bansiPc=</ICommand_Default_Password>
<Communication_Protocol>t3</Communication_Protocol>
<SensorFactory>oracle.bam.common.statistics.noop.SensorFactoryImpl</SensorFactory>
<GenericSatelliteChannelName>invm:topic/oracle.bam.messaging.systemobjectnotification</GenericSatelliteChannelName>
</BAMICommand>

Default password should be encrypted else you will be receiving “ICommandEngine.MissingCredentials” error.

To encrypt the password configure the BAMICommandConfig.xml file in the $ORACLE_HOME/bam/config folder with the plain text password and run any standard icommand from the server (e.g $ORACLE_HOME/bam/bin/icommand -cmd export -type dataobject -name SampleDO -file C:\temp\SampleDO.xml) that will encrypt the password.
  • Create Export_BAM_Objects.xml file with the BAM export commands and place the same in BAMConfig folder created in the above step, the contents of the file look like below
<OracleBAMCommands>
   <!--import dataobjects-->
    <Export name="/Albin/BAMWebservice" type="dataobject" file="$BAM_PROJ_HOME$/BAMWebservice.xml"/>
    <Export name="/SampleDO" type="dataobject" file="$BAM_PROJ_HOME$/SampleDO.xml"/>
</OracleBAMCommands>
Configure the required export commands (exporting different type of objects) into this file.
  • Create Import_BAM_Objects.xml file with the BAM import commands and place the same in BAMConfig folder created in the above step, the contents of the file look like below
<OracleBAMCommands>
   <!--import dataobjects-->
   <Import file="$BAM_PROJ_HOME$/BAMWebservice.xml"/>
</OracleBAMCommands>
Configure the required import commands into this file.
  • Create the BAMBuild.xml file with the following contents and place the same in the BAMConfig folder created in the above step.
<project name="BAMMigrationProject" basedir="." default="config">
   <!--import the property file-->
   <property environment="env"/>
   <property name="src.dir" value="."/>
   <property name="proj.home" value="${env.BAM_PROJ_HOME}"/>
   <property name="oracle.home" value="${env.ORACLE_HOME}"/>
   <property name="oracle.common.home" value="${env.ORACLE_COMMON_HOME}"/>
   <property name="bam.core.lib.dir" value="${env.ORACLE_HOME}/bam/modules/oracle.bam_11.1.1"/>
   <property name="bam.tp.lib.dir" value="${env.ORACLE_HOME}/bam/modules/oracle.bam.thirdparty_11.1.1"/>
   <property name="dms.lib.dir" value="${env.ORACLE_COMMON_HOME}/modules/oracle.dms_11.1.1"/>
   <!--BAM Classpath required by icommand application-->
   <path id="bamClasspath">
      <fileset file="${bam.core.lib.dir}/oracle-bam-icommand.jar"/>
      <fileset file="${bam.core.lib.dir}/oracle-bam-common.jar"/>
      <fileset file="${bam.core.lib.dir}/oracle-bam-adc-ejb.jar"/>
      <fileset file="${dms.lib.dir}/dms.jar"/>
      <fileset file="${bam.tp.lib.dir}/jgroups-core.jar"/>
      <fileset file="${bam.tp.lib.dir}/xstream-1.3.1.jar"/>
      <fileset file="${bam.tp.lib.dir}/commons-codec-1.3.jar"/>
      <fileset file="${oracle.home}/../wlserver_10.3/server/lib/weblogic.jar"/>
      <fileset file="${oracle.common.home}/modules/org.jaxen_1.1.1.jar"/>
   </path>
   <!--export BAM DOs through icommand-->
   <target name="export" description="Export BAM dataobjects and reports" depends="config">
    <delete dir="${basedir}/BAMObjects" includeemptydirs="true" includes="*/**"></delete>
      <java classname="oracle.bam.icommand.Application" fork="true" dir="${src.dir}" classpathref="bamClasspath">
         <sysproperty key="oracle.bam.debug" value="true"/>
         <arg value="-CmdFile"/>
         <arg value="${basedir}/Export_BAM_Objects.xml"/>
      </java>
   </target>
   <!--import BAM DOs through icommand-->
   <target name="import" description="Import BAM dataobjects and reports" depends="config">
      <java classname="oracle.bam.icommand.Application" fork="true" dir="${src.dir}" classpathref="bamClasspath">
         <sysproperty key="oracle.bam.debug" value="true"/>
         <arg value="-CmdFile"/>
         <arg value="${basedir}/Import_BAM_Objects.xml"/>
      </java>
   </target>
   <!--Modify bam icommand files-->
   <target name="config">
       <!--replace $project.home$ with the actual project directory inside the command file-->
      <replace file="Export_BAM_Objects.xml" token="$BAM_PROJ_HOME$" value="${basedir}/BAMObjects"/>
      <replace file="Import_BAM_Objects.xml" token="$BAM_PROJ_HOME$" value="${basedir}/BAMObjects"/>
   </target>
</project>
  • To run the scripts from the server copy the BAMConfig folder with all the contents to the server.Set the environment variables ORACLE_HOME and ORACLE_COMMON_HOME(e.gORACLE_HOME=/oracle/Middleware/Oracle_SOA1;export ORACLE_HOME;ORACLE_COMMON_HOME=oracle/Middleware/oracle_common;export ORACLE_COMMON_HOME) and also set the PATH to ANT(e.g export PATH=$PATH:$ORACLE_HOME/../modules/org.apache.ant_1.7.1/bin)
         Execute the ant scripts
          ant –f BAMBuild.xml export

        The objects will be exported based on the commands in the Export_BAM_Objects.xml as an xml file   to the BAMObjects folder

         ant –f BAMBuild.xml import

           The xml file contents will be imported to BAM based on the commands in the Import_BAM_Objects.xml
  • To run the script from the client machine the JDeveloper with the same version as the BAM server should be installed.Set the ORACLE_HOME (e.g C:\EnvSetup\MiddlewareBlog\jdeveloper) and ORACLE_COMMON_HOME(e.g C:\EnvSetup\MiddlewareBlog\oracle_common) environment variables and also set the PATH to ANT
        Copy the commons-codec-1.3.jar file from the server location   ${env.ORACLE_HOME}/bam/modules/oracle.bam.thirdparty_11.1.1 to the <JDEV_HOME>\ jdeveloper\bam\modules\oracle.bam.thirdparty_11.1.1

Run the ant script


Wednesday, February 13, 2013

Different integration approaches to send the event data to Oracle BAM 11g

Different integration approaches to send the event data to Oracle BAM 11g

Oracle BAM provides a framework for Creating dashboards that display real-time data based on the events.
There are multiple approaches to send the event data to Oracle BAM.This document explains some of the approaches to send the data toOracle BAM.

Different approaches to send event data to BAM


Friday, December 21, 2012

Building a Simple Oracle ADF page using Oracle BAM Data Control

Building a Simple Oracle ADF page using Oracle BAM Data Control

This blog will explain how to Build a Simple Oracle ADF page using Oracle BAM Data Control

The Oracle BAM reports can be built through BAM Active Studio or through BAM data control in Oracle ADF page.
In this blog I will be explaining about the steps required to build a simple ADF page using BAM data control.

Creating the BAM Connection:

  • Open the JDeveloper
  • Create new BAM Connection

  • Enter the BAM Server details as shown below. 

  • Click on Finish and Test the connection
  • Create the data object in BAM through Architect view (I am using the existing data object Employee)



Thursday, December 20, 2012

Runtime Exception in Oracle ADF application with Oracle BAM Data Control - Failed handling event FirstGetOnDataProvider on QueryConfigured

Runtime Exception in Oracle ADF application with Oracle BAM Data Control - Failed handling event FirstGetOnDataProvider on QueryConfigured


We may receive the following exception while running the Oracle ADF application with Oracle BAM Data Control configured into that.

<Dec 19, 2012 3:07:06 AM PST> <Error> <oracle.tip.tools.ide.bam.dc.rt.fsm.StateMachine> <BEA-000000> <Failed handling event FirstGetOnDataProvider on QueryConfigured>
<Dec 19, 2012 3:07:06 AM PST> <Warning> <oracle.adf.controller.faces.lifecycle.Utils> <BEA-000000> <ADF: Adding the following JSF error message: Failed handling event FirstGetOnDataProvider on QueryConfigured
oracle.tip.tools.ide.bam.dc.rt.fsm.exception.TransitionFailureException: Failed handling event FirstGetOnDataProvider on QueryConfigured
        at oracle.tip.tools.ide.bam.dc.rt.fsm.StateMachine.internalHandle(StateMachine.java:249)
        at oracle.tip.tools.ide.bam.dc.rt.fsm.StateMachine.handle(StateMachine.java:151)
        at oracle.tip.tools.ide.bam.dc.rt.provider.paging.PagingCollection$PagingIterator.<init>(PagingCollection.java:272)
        at oracle.tip.tools.ide.bam.dc.rt.provider.paging.PagingCollection$PagingIterator.<init>(PagingCollection.java:234)
        at oracle.tip.tools.ide.bam.dc.rt.provider.paging.PagingCollection.iterator(PagingCollection.java:152)
        at oracle.adf.model.bean.DCDataVO.buildProviderIterator(DCDataVO.java:1319)
        at oracle.adf.model.bean.DCDataVO.access$100(DCDataVO.java:86)
        at oracle.adf.model.bean.DCDataVO$DCObjectAdapter.refreshIterator(DCDataVO.java:2923)
        at oracle.adf.model.bean.DCDataVO.executeQueryForCollection(DCDataVO.java:404)
        at oracle.tip.tools.ide.bam.dc.dt.adapter.BAMDataControlDataVO.executeQueryForCollection(BAMDataControlDataVO.java:83)
        at oracle.jbo.server.ViewRowSetImpl.execute(ViewRowSetImpl.java:1217)
        at oracle.jbo.server.ViewRowSetImpl.executeQueryForMasters(ViewRowSetImpl.java:1397)
        at oracle.jbo.server.ViewRowSetImpl.executeQueryForMode(ViewRowSetImpl.java:1303)
        at oracle.jbo.server.ViewRowSetImpl.executeQuery(ViewRowSetImpl.java:1288)
        at oracle.jbo.server.ViewObjectImpl.executeQuery(ViewObjectImpl.java:7107)
        at oracle.adf.model.bean.DCBeanDataControl.executeIteratorBindingIfNeeded(DCBeanDataControl.java:990)
        at oracle.tip.tools.ide.bam.dc.dt.adapter.BAMAdapterDCService.executeIteratorBindingIfNeeded(BAMAdapterDCService.java:235)
        at oracle.adf.model.binding.DCIteratorBinding.executeQueryIfNeeded(DCIteratorBinding.java:2160)
        at oracle.jbo.uicli.binding.JUCtrlHierBinding.getRootNodeBinding(JUCtrlHierBinding.java:95)
        at oracle.adfinternal.view.faces.model.binding.RowDataManager.getParent(RowDataManager.java:251)
        at oracle.adfinternal.view.faces.model.

The issue is because of the BAM connection details are not configured in the EM console after the deployment of the application.

If we are deploying the application to the stand alone server, the Oracle BAM connection must be re-created in Oracle Fusion Middleware Control Console after the deployment of the application.
Also application must be deployed using MDS enabled otherwise the connection details will not be persisted.

Steps to resolve this issue:

Enable the MDS for the Application:

  • Right click on the project and Select Project Properties.


Problem while deploying Oracle ADF application - java.lang.ClassNotFoundException: oracle.adf.library.webapp.ResourceServlet

Problem while deploying Oracle ADF application - java.lang.ClassNotFoundException: oracle.adf.library.webapp.ResourceServlet


Sometimes we may receive the following exception while deploying the Oracle ADF application to the server.

weblogic.application.ModuleException: Failed to load webapp: 'BAPReport.war'
        at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:395)
        at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:176)
        at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)
        at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:517)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassNotFoundException: oracle.adf.library.webapp.ResourceServlet
        at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
        at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)
        at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        Truncated. see log file for complete stacktrace
The issue is the oracle.adf.library.webapp.ResourceServlet class is missing in the class path.This issue can be resolved by deploying the application as EAR file instead of deploying the project as WAR file.

Steps to resolve the issue:

  • Right click on the application and select Application properties

  • Select Deployment and click on New



Tuesday, December 18, 2012

Send the reports to external email ids through Alerts - Oracle BAM server.

Send the reports to external email ids through Alerts - Oracle BAM server.

By default we can’t send the reports to an external email id’s from a Oracle BAM server, the reports only can be send to a users configured with Oracle BAM servers(through weblogic console).This post will explain how to enable the Oracle BAM server to send the reports to the external email ids.

Before following this post the email drivers details should be configured in UMS (through em console).

By default AlertActionAllowExternalEmail property in the BAMCommonConfig.xml file is set as false.
Change the value of AlertActionAllowExternalEmail property to true in the BAMCommonConfig.xml file to enable the external email feature. The BAMCommonConfig.xml file can be located in the following location BAM_DOMAIN_HOME/BAMDomain/config/fmwconfig/servers/BAMManagedServer/applications/oracle-bam_11.1.1/config.

 Create an Alert to send the report to the External Email:

  • Login to the Architect window; select the Alert from the drop down list and click on Create New Alert.



Wednesday, December 12, 2012

Creating report based on External Data Source (Database table) – Oracle BAM

Creating report based on External Data Source  (Database table) – Oracle BAM


In Oracle BAM the reports can be created based on the external database table.This post will explain the steps required to build a simple report based on the external database table.

Create the External Database:

  • Login to Oracle BAM Start page and click on Architect button.


  • Select External Data Sources from the drop down list and click on the create button in the next page.

  • Provide the External Datasource Name and the database details and click on the Test button to test the External Data Source.


Tuesday, October 30, 2012

The server does not support version 3.0 of the J2EE Web module specification - Eclipse

The server does not support version 3.0 of the J2EE Web module specification -  Eclipse

Sometimes we used to receive the following exception when running the web application in latest eclipse version.

The server does not support version 3.0 of the J2EE Web module specification.

The issue is when creating the web project in latest eclipse by default the web version  will be selected as 3.0 but the server what we are having is not supporting the web 3.0.

There is two options to fix this issue.

1. Upgrade your server to latest version
2.Open org.eclipse.wst.common.project.facet.core.xml file from /workspace/<Your project name>/.settings and change jst.web version to 2.5 instead 3.0

<installed facet="jst.web" version="2.5"/>





Thursday, October 25, 2012

Auto Submitting the HTML page on load

Auto Submitting the HTML page on load - Auto Submitting the HTML page on load:


<html>
<head>
<script>
window.onload = function()
{
 document.login.submit();
}
</script>
</head>
<body>
<FORM name="login" action="http://localhost:7001/analytics/saw.dll?bieehome" method="post">
    <INPUT type="hidden" name="nQUser" value="weblogic">
    <INPUT type="hidden" name="nQPassword" value="weblogic123">
   </FORM>
 </FRAMESET>
 </body>
</html>


Monday, September 3, 2012

Configuring BAM web application properties – Oracle SOA Suite


Configuring BAM web application properties – Oracle SOA Suite

The BAM web application properties should be configured before designing the reports in Oracle BAM, these properties will be configured in reports.

Steps to configure the BAM web application properties

  • Login to EM console and maximize the BAM node
  • Click on OracleBamWeb and click on BAM Web Properties

  • Change the application URL and the Server name as shown below (port should be the BAM server port) and Click on Apply


Saturday, August 25, 2012

Problem while accessing the Oracle ADF application - java.lang.NoClassDefFoundError:oracle/jbo/common/SessionContextManagerImpl


Problem while accessing the Oracle ADF application - java.lang.NoClassDefFoundError:oracle/jbo/common/SessionContextManagerImpl

The following exception was thrown while accessing the Oracle ADF application deployed to the server.

java.lang.NoClassDefFoundError: oracle/jbo/common/SessionContextManagerImpl
                at oracle.adf.model.BindingRequestHandler.endRequest(BindingRequestHandler.java:326)
                at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:210)
                at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
                at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:106)

The issue is SessionContextManagerImpl class is missing from the classpath.

Steps to resolve the issue: 

  • Right click on the project and click on Project properties.
  •  Select the Libraries and Classpath and click on Add Library


Friday, August 17, 2012

Problem while deploying Oracle ADF application - java.lang.ClassNotFoundException: oracle.adf.model.servlet.ADFBindingFilter

Problem while deploying Oracle ADF application - java.lang.ClassNotFoundException: oracle.adf.model.servlet.ADFBindingFilter

The following exception was thrown while deploying the Oracle ADF application to the server.

[08:38:30 PM] Weblogic Server Exception: weblogic.application.ModuleException: Failed to load webapp: 'ADF_OSR_ViewController_webapp1.war'
[08:38:30 PM] Caused by: java.lang.ClassNotFoundException: oracle.adf.model.servlet.ADFBindingFilter
[08:38:30 PM]   See server logs or server console for more details.
[08:38:30 PM] weblogic.application.ModuleException: Failed to load webapp: 'ADF_OSR_ViewController_webapp1.war'
[08:38:30 PM] ####  Deployment incomplete.  ####
[08:38:30 PM] Remote deployment failed

The issue is the ADFBindingFilter class is missing in the class path.

Steps to resolve the issue:

  • Right click on the project and click on Project properties.
  • Select the Deployment, the deployment profile and click on edit button.


java.lang.RuntimeException: Cannot find FacesContext

java.lang.RuntimeException: Cannot find FacesContext

Some time we may receive the below exception while accessing the JSF pages.

java.lang.RuntimeException: Cannot find FacesContext
 at javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:2122)
 at javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1933)
 at jsp_servlet.__employeedetails._jsp__tag0(__employeedetails.java:135)
 at jsp_servlet.__employeedetails._jspService(__employeedetails.java:110)
 at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)

The issue is due to the faces servelet has not been initialized.

The cause is the URL used to access the page is wrong like
http://10.136.211.120:7001/ADF_OSR-ViewController-context-root/EmployeeDetails.jsp

The URL should be like
http://localhost:7001/ADF_OSR-ViewController-context-root/faces/EmployeeDetails.jsp



Monday, August 13, 2012

Publishing the services to Oracle Service registry through JDeveloper

Publishing the services to Oracle Service registry through JDeveloper

The composites services deployed in the Oracle SOA Suit Serves can be published to Oracle Service registry and the same can be consumed by the client application by looking up the services from the Service Registry.

This blog explains the steps to publish the services deployed in the Oracle SOA Suit server to Oracle Service registry.

Create the Business Entity in the Oracle Service registry:

A business entity represents an organization or group of people responsible for a set of services (a service provider).
  • Login to Registry console
  • Select Publish tan and select Business
  • Click on Add Business Button; enter the Business name and the description



Friday, August 10, 2012

Oracle Service Registry Part 1 – Installing 11.1.1.6.0 version in Standalone mode

Oracle Service Registry Part 1 – Installing 11.1.1.6.0 version in Standalone mode:

Oracle Service Registry (OSR) is a fully V3-compliant implementation of UDDI (Universal Description, Discovery and Integration), and one of the key components of Oracle SOA Suite 11g.

It allows us to publish and discover services and service providers, and manage metadata about services (security, transport, or quality service) using taxonomies. Therefore, it plays an important role when trying to improve visibility and promote service reuse. It is also important in the scope of SOA governance.
A service registry is very important for various reasons. It provides a central place where all service definitions are stored.

A service registry also provides a central place where developers can search for existing services
This improves service reuse, which is one of the most important aspects of SOA.
The Oracle Service Registry 11g can be installed on the following modes.

Standalone Registry:

Installs a standalone registry allowing the creation of a new registry database. The installed registry will be usable without other registry installations unlike Discovery, Publication or Intermediate options.

Discovery Registry:

Installs a discovery registry. The discovery registry contains approved data that have been posted from the publication registry. The discovery registry is under full control of approvers.

Publication registry:

Installs a publication registry. The publication registry is used for testing and verification of data. Important! To install the publication server you must have an installed discovery server because the discovery registry certificate is needed.

Intermediate Registry:

Installs this instance as an intermediate registry, which acts as both a Publication Registry and a Discovery Registry. That is, it is deployed in-between other Registries to support a multi-step approval process. Note that the final Discovery Registry must be installed prior to installing the Intermediate registry, since the Discovery Registry's certificate is needed to complete installation process.

Create the database Schema – OSR:

The database schema will hold all the Service Registry metadata’s
Execute the below sql to create the OSR schema.

CREATE TABLESPACE OSR_TABLESPACE LOGGING
 DATAFILE 'OSR.DBF' SIZE 50M REUSE AUTOEXTEND
 ON NEXT 10M MAXSIZE UNLIMITED
 DEFAULT STORAGE (
  INITIAL 5M
  NEXT 5M
  MINEXTENTS 1
  MAXEXTENTS UNLIMITED
  PCTINCREASE 50);

CREATE USER OSR
 PROFILE DEFAULT
 IDENTIFIED BY blogenv
 DEFAULT TABLESPACE OSR_TABLESPACE
 TEMPORARY TABLESPACE TEMP
 ACCOUNT UNLOCK;

GRANT CONNECT TO OSR;
GRANT RESOURCE TO OSR;
GRANT UNLIMITED TABLESPACE TO OSR;
GRANT CREATE ANY SYNONYM TO OSR;
GRANT DROP ANY SYNONYM TO OSR;
  • Download Oracle Weblogic Server 11g and OSR 11.1.1.6.0
  • Install Oracle Weblogic Server.
  • Double click on OSR111160_generic_.jar to install the OSR.
  • Select the Installation type as Standalone Registry



Friday, July 20, 2012

Splitting an array of repeated elements into sub groups based on index in XSL

Splitting an array of repeated elements into sub groups based on index in XSL

Sometimes we may require splitting the array of repeated elements into sub groups based on index in XSL; this blog will explain the approach to do the same.

The below XSLT will select the first two order line items from the list of line items.
The same can be used to select the elements by passing startIndex and endIndex values.

<xsl:stylesheet version="1.0"
                xmlns:xsdLocal="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="startIndex">1</xsl:variable>
<xsl:variable name="endIndex">2</xsl:variable>
  <xsl:template match="/">
    <xsdLocal:orderRequest>
      <xsl:for-each select="/xsdLocal:UserIdRequest/xsdLocal:orderLineItem[(position() >= $startIndex) and (position() &lt;= $endIndex)]">
        <xsdLocal:orderLineItem>
          <xsdLocal:CRMOLIId>
            <xsl:value-of select="xsdLocal:CRMOLIId"/>
          </xsdLocal:CRMOLIId>
          <xsdLocal:parentOrderItemId>
            <xsl:value-of select="xsdLocal:parentOrderItemId"/>
          </xsdLocal:parentOrderItemId>
          <xsdLocal:rootItemId>
            <xsl:value-of select="xsdLocal:rootItemId"/>
          </xsdLocal:rootItemId>
      </xsdLocal:orderLineItem>
      </xsl:for-each>
    </xsdLocal:orderRequest>
  </xsl:template>
</xsl:stylesheet>

Input XML:

<?xml version="1.0" encoding="UTF-8" ?>
<UserIdRequest  xmlns="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement">
  
   <orderLineItem>
      <CRMOLIId>CRMOLIId529</CRMOLIId>
      <parentOrderItemId>parentOrderItemId530</parentOrderItemId>
      <rootItemId>rootItemId531</rootItemId>
    
   </orderLineItem>
   <orderLineItem>
        <CRMOLIId>CRMOLIId529</CRMOLIId>
      <parentOrderItemId>parentOrderItemId530</parentOrderItemId>
      <rootItemId>rootItemId531</rootItemId>
   </orderLineItem>
   <orderLineItem>
       <CRMOLIId>CRMOLIId529</CRMOLIId>
      <parentOrderItemId>parentOrderItemId530</parentOrderItemId>
      <rootItemId>rootItemId531</rootItemId>
   </orderLineItem>
  
    <orderLineItem>
       <CRMOLIId>CRMOLIId529</CRMOLIId>
      <parentOrderItemId>parentOrderItemId530</parentOrderItemId>
      <rootItemId>rootItemId531</rootItemId>
   </orderLineItem>
  
    <orderLineItem>
       <CRMOLIId>CRMOLIId529</CRMOLIId>
      <parentOrderItemId>parentOrderItemId530</parentOrderItemId>
      <rootItemId>rootItemId531</rootItemId>
   </orderLineItem>
  
    <orderLineItem>
       <CRMOLIId>CRMOLIId529</CRMOLIId>
      <parentOrderItemId>parentOrderItemId530</parentOrderItemId>
      <rootItemId>rootItemId531</rootItemId>
   </orderLineItem>
</UserIdRequest>

Output XML:

<?xml version = '1.0' encoding = 'UTF-8'?>
<xsdLocal:orderRequest xmlns:xsdLocal="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement file:/D:/Albin/DevCodeBase/2012_R5/CRM_EAI_code_deploy/code/CRM61OM/CPFGOM_OrderSplitter/EAI.MSG.OM.125_OrderRequest.xsd">
   <xsdLocal:orderLineItem>
      <xsdLocal:CRMOLIId>CRMOLIId529</xsdLocal:CRMOLIId>
      <xsdLocal:parentOrderItemId>parentOrderItemId530</xsdLocal:parentOrderItemId>
      <xsdLocal:rootItemId>rootItemId531</xsdLocal:rootItemId>
   </xsdLocal:orderLineItem>
   <xsdLocal:orderLineItem>
      <xsdLocal:CRMOLIId>CRMOLIId529</xsdLocal:CRMOLIId>
      <xsdLocal:parentOrderItemId>parentOrderItemId530</xsdLocal:parentOrderItemId>
      <xsdLocal:rootItemId>rootItemId531</xsdLocal:rootItemId>
   </xsdLocal:orderLineItem>
</xsdLocal:orderRequest>


Finding the distinct values of an element in a XSL


Finding the distinct values of an element in a XSL

Sometimes we may have the requirement to identify the distinct elements in the input XML. Key function will help us to identify the distinct elements in the XSL.

The key () function returns a node-set from the document, using the index specified by an <xsl:key> element.

Syntax:

node-set key(string, object)
string - Specifies the name of an xsl:key element
object - A string to search for

The below XSL will find the distinct nextaction1 available in the XML.

TransDistinctNextAction1.xsl

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsdLocal="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement">
  <xsl:key name="orderlines-by-n1" match="/xsdLocal:extendedOrderRequest/xsdLocal:orderLineItem" use="xsdLocal:nextAction1"/>
 
  <xsl:template match="/">
    <xsdLocal:distinctNextActions>
      <xsdLocal:nextAction>
        <xsdLocal:nextAction1>
          <xsl:for-each select="/xsdLocal:extendedOrderRequest/xsdLocal:orderLineItem[generate-id(.) = generate-id( key('orderlines-by-n1', xsdLocal:nextAction1)[1])]">
            <xsdLocal:value>
              <xsl:value-of select="xsdLocal:nextAction1"/>
            </xsdLocal:value>
          </xsl:for-each>
        </xsdLocal:nextAction1>       
      </xsdLocal:nextAction>
    </xsdLocal:distinctNextActions>
  </xsl:template>
</xsl:stylesheet>


  <xsl:key name="orderlines-by-n1" match="/xsdLocal:extendedOrderRequest/xsdLocal:orderLineItem" use="xsdLocal:nextAction1"/>

                      Find the orderLineItems based on the nextaction1

          <xsl:for-each select="/xsdLocal:extendedOrderRequest/xsdLocal:orderLineItem[generate-id(.) = generate-id( key('orderlines-by-n1', xsdLocal:nextAction1)[1])]">

                        Find the unique nextaction1 values from the orderLineItems

Input XML:

<?xml version="1.0" encoding="UTF-8" ?>
<extendedOrderRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement">
  
    <orderLineItem>
      <CRMOLIId>CRMOLIId36</CRMOLIId>
      <rootItemId>rootItemId37</rootItemId>
      <parentOrderItemId>parentOrderItemId38</parentOrderItemId>
      <actionCode>actionCode39</actionCode>     
      <nextAction1>nextAction175</nextAction1>     
   </orderLineItem>
   <orderLineItem>
      <CRMOLIId>CRMOLIId36</CRMOLIId>
      <rootItemId>rootItemId37</rootItemId>
      <parentOrderItemId>parentOrderItemId38</parentOrderItemId>
      <actionCode>actionCode39</actionCode>     
      <nextAction1>nextAction175</nextAction1>
   </orderLineItem>
   <orderLineItem>
      <CRMOLIId>CRMOLIId36</CRMOLIId>
      <rootItemId>rootItemId37</rootItemId>
      <parentOrderItemId>parentOrderItemId38</parentOrderItemId>
      <actionCode>actionCode39</actionCode>     
      <nextAction1>nextAction17</nextAction1>
   </orderLineItem>
</extendedOrderRequest>

Output XML:

<?xml version = '1.0' encoding = 'UTF-8'?>
<xsdLocal:distinctNextActions xmlns:xsdLocal="http://www.reuters.com/ns/2007/01/25/GCAP/EAI/OrderManagement" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <xsdLocal:nextAction>
      <xsdLocal:nextAction1>
         <xsdLocal:value>nextAction175</xsdLocal:value>
         <xsdLocal:value>nextAction17</xsdLocal:value>
      </xsdLocal:nextAction1>
   </xsdLocal:nextAction>
</xsdLocal:distinctNextActions>