4 Replies Latest reply on Aug 1, 2011 3:00 PM by Neeraj Sehgal

    Filtering elements in an XML based on criteria

      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
          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
            hi Veer,

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


            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");
            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..

            • 3. Re: Filtering elements in an XML based on criteria
              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
                Neeraj Sehgal

                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_'))]"> 
                Neeraj Sehgal