Search code examples
xmlxsltxsdbpel

Use the counter variable from a for-each loop into an XSLT in soa BPEL


I am invoking a webservice from a BPEL process. The webservice accepts below parameters:

<xsd:element name="Documents" minOccurs="0" nillable="true"
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="Entry" minOccurs="0" nillable="true" maxOccurs="unbounded">
      <xsd:complexType>
    <xsd:sequence>
<xsd:element name="url" minOccurs="0" nillable="true" type="xsd:string
<xsd:element name="ID" minOccurs="0" nillable="true" type="xsd:string" >
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

The requests that I receive have multiple entries. So I am using a <for-each> loop. The <for-each> loop counts the number of entries present and loops as per the count. For example, if I have 3 entries, the <for-each> loop invokes the webservice three times (that is what I want).

But everytime it invokes, it only passes the first entry. Before invoking the webservice, I am using a transform activity and an XSLT. I want to define the XSLT in such a way that it will invoke on the current count value.

For example:

if count = 1.. entry 1 is transformed
If count = 2.. entry 2 is transformed.

The XSLT that I am stuck with is below: I am using the position function and want to assign it to count variable. When I hard code something like position() = 1, or position() = 2, it works fine and pulls up the entry I need. But how would I set it at runtime?

Is using position() the correct option or can I use something else?

Note: count is defined initially while starting the <for-each> loop and I am setting it as per the entries.

Sorry for such a long question, but I hope someone has an answer for it.

Thanks in advance

<tns:Documents>
<xsl:for-each       select="/ns0:request/ns0:Documents/ns0:Entry[position()==?????]">    
<tns:Entry>
<tns:Url>
<xsl:value-of select="ns0:Url"/>
</tns:Url>
<tns:ID>
<xsl:value-of select="ns0:ID"/>
</tns:ID>
</tns:Entry>
</xsl:for-each>
</tns:Documents>

Solution

  • Why are you using (or: trying to use) position() on the xsl:for-each/@select attribute?

    You have three requests. For each request, you want to invoke a web service. In pseudo-code, the structure you want is

    <xsl:for-each select="path/to/all/my-requests">
      <!--* invoke web service ... *-->
    </xsl:for-each>