This discussion is archived
4 Replies Latest reply: Aug 1, 2011 8:00 AM by NeerajSehgal RSS

Filtering elements in an XML based on criteria

695116 Newbie
Currently Being Moderated
we have an output schema that has some repeating elements. There is some meta-data in the output XML that we are trying to filter out in the final output. Since this transformation is between the same input/output XML, I am trying to achieve this using transform activity. How can we use XSLT constructs in the transformation activity to achieve this. For example:

Records (parent)
-->Record (child unbounded)
--> Id (attribute of Record element)
--> name (attribute of Record element)

If we have a list of record elements, we want to filter/remove all the record elements that starts with name="meta__" in the output XML
  • 1. Re: Filtering elements in an XML based on criteria
    695116 Newbie
    Currently Being Moderated
    Okay, I was just waiting to see whether anyone has a similar scenario, but I already got it to work right after I posted here, but It doesn't look clean. We can filter elements with certain ids with XSL:IF & passing the keys for comparision in the condition. So lets say if we have 25 elements that start with given name with the same prefix, we have to write 25 XSL:IF conditions & give the element attribute key in the comparision condition.
    What I am wondering is if there is anyway where we can specify the prefix in a single XSL:IF condition to remove all the elements starting with the same prefix.


    Thanks for your time.
  • 2. Re: Filtering elements in an XML based on criteria
    686542 Explorer
    Currently Being Moderated
    hi Veer,

    I have achieved the same using java API. This is the block of code, through which i achieved

    com.oracle.bpel.client.IBPELProcessHandle
    com.oracle.bpel.client.IInstanceHandle
    com.oracle.bpel.client.Locator
    com.oracle.bpel.client.ServerException

    This four API's will help us to communicate with OC4j instance and we can get relevant xml element, in my case i have retrieved input variable from audit instance data.

    IBPELProcessHandle processHandle = connectOC4J();
    IInstanceHandle instanceHandle = getInstanceHandle(processHandle,instanceID);
    String Title = instanceHandle.getTitle();
    String processId = instanceHandle.getParentId();
    String Status = instanceHandle.getStatus();
    HashMap AuditTrail = (HashMap)instanceHandle.getField("inputVariable");
    System.out.println(Title+"\t"+processId+"\t"+Status+"\t");
    Set keySet = AuditTrail.keySet();
    Iterator it = keySet.iterator();
    for(int k=0;k<AuditTrail.size()&&it.hasNext();k++){
    String key = (String)it.next();
    Element value = (Element) AuditTrail.get(key); // Element contains input variable data..

    Hope this helps you..

    regards
    Rajesh
  • 3. Re: Filtering elements in an XML based on criteria
    695116 Newbie
    Currently Being Moderated
    Thanks Rajesh. Old thread. Marking this thread as Answered, since I choose a way to filter it in XSLT with dirty IF statement
  • 4. Re: Filtering elements in an XML based on criteria
    NeerajSehgal Journeyer
    Currently Being Moderated
    Hi,

    Just for the help of others:

    We can use conditional for-each to consider only elements that do not start with meta_ and ignoring others.
     <xsl:for-each select="Records/Record[not(starts-with(name,'meta_'))]"> 
    Regards,
    Neeraj Sehgal

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points