简体   繁体   中英

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>

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>

Your XSD file was not well-formed . I did not edit your question regarding to this issue, because it would have been destructive to the cause of your question.

So here, I corrected some flaws of your question: this is the result of well-forming your input:

<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>

Your well-formed XSLT looks like this:

<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>

These are the facts . You didn't have provided an extended XSLT to transform these two data-sets to anything to resolve this so far. It would be constructive to provide an XSL to resolve your issue, don't you think? :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM