Sagar Pahlajani
Sagar Pahlajani

Reputation: 45

Pull the nested tag in For loop in XSLT

I have to pull each party site->city and state information and concat them in one single string. In this I am trying to loop but it is pulling up one first iteration of the XML child. Need help in getting all city and state value clubbed together in a variable. I need suggestion to pull the tag and store in variable too.

I need to store the variable like "Quispamsis,NB,#Edmonton,AB"

    ```XMLCode


<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:typ="http://xmlns.oracle.com/apps/cdm/foundation/parties/organizationService/applicationModule/types/">
   <env:Header>
      <wsa:Action>http://xmlns.oracle.com/apps/cdm/foundation/parties/organizationService/applicationModule//OrganizationService/getOrganizationResponse</wsa:Action>
      <wsa:MessageID>urn:uuid:fb4115fd-ca76-4cec-9bac-a437fde6b7d5</wsa:MessageID>
   </env:Header>
   <env:Body>
      <ns0:getOrganizationResponse xmlns:ns0="http://xmlns.oracle.com/apps/cdm/foundation/parties/organizationService/applicationModule/types/">
         <ns3:result xsi:type="ns2:OrganizationParty" xmlns:ns2="http://xmlns.oracle.com/apps/cdm/foundation/parties/organizationService/" xmlns:ns1="http://xmlns.oracle.com/apps/cdm/foundation/parties/partyService/" xmlns:ns3="http://xmlns.oracle.com/apps/cdm/foundation/parties/organizationService/applicationModule/types/" xmlns:ns0="http://xmlns.oracle.com/adf/svc/types/" xmlns:ns5="http://xmlns.oracle.com/apps/cdm/foundation/parties/contactPointService/" xmlns:ns8="http://xmlns.oracle.com/apps/cdm/foundation/parties/relationshipService/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ns2:PartyNumber>CDRM_1167</ns2:PartyNumber>
            <ns2:PartySite xmlns:ns7="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/partySite/">
               <ns1:PartySiteId>300000012822376</ns1:PartySiteId>
               <ns1:PartyId>300000012822366</ns1:PartyId>


               <ns1:Country>CA</ns1:Country>

               <ns1:City>Quispamsis</ns1:City>
               <ns1:PostalCode>56987</ns1:PostalCode>
               <ns1:State>NB</ns1:State>

          </ns2:PartySite>
          <ns2:PartySite xmlns:ns7="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/partySite/">
               <ns1:City>Edmonton</ns1:City>
               <ns1:PostalCode xsi:nil="true"/>
               <ns1:State>AB</ns1:State>
            </ns2:PartySite>
 </ns3:result>
      </ns0:getOrganizationResponse>
   </env:Body>
</env:Envelope>
```

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sb1="urn:crmondemand/ws/account/10/2004" 
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://xmlns.oracle.com/apps/cdm/foundation/parties/organizationService/applicationModule/types/" 
xmlns:ns1="http://xmlns.oracle.com/apps/cdm/foundation/parties/partyService/" xmlns:ns2="http://xmlns.oracle.com/apps/cdm/foundation/parties/organizationService/" xmlns:ns3="http://xmlns.oracle.com/apps/cdm/foundation/parties/organizationService/applicationModule/types/" version="1.0">



<xsl:template match="/">
<xsl:variable name="main_doc" select="/env:Envelope/env:Body/ns0:getOrganizationResponse/ns3:result"/>
<xsl:variable name="site">
    <xsl:for-each select="$main_doc/ns2:PartySite">
        <xsl:choose>
            <xsl:when test="position() = 1">
                <xsl:value-of select="concat(./ns1:City,',',./ns1:State)"/>
            </xsl:when>
            <xsl:otherwise>
                ;<xsl:value-of select="concat(./ns1:City,',',./ns1:State)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
</xsl:variable>
<html> 
<body>
  <h2>My CD Collection</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th style="text-align:left">Title</th>
      <th style="text-align:left">Artist</th>
    </tr>
<xsl:for-each select="$main_doc">

   <tr>
      <td><xsl:value-of select="$main_doc/ns2:PartyId"/></td>
      <td><xsl:value-of select="concat($main_doc/ns2:PartyName,',', $main_doc/ns2:PartyNumber)"/></td>
        <td><xsl:value-of select="$site"/></td>
<xsl:for-each select="./ns2:PartySite">

          <td><xsl:value-of select="./ns1:City"/></td>

</xsl:for-each>
   </tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Upvotes: 0

Views: 64

Answers (1)

Tim C
Tim C

Reputation: 70638

If you want your site variable to be contain the text Quispamsis,NB,#Edmonton,AB, then you can just do this....

<xsl:variable name="site">
    <xsl:for-each select="$main_doc/ns2:PartySite">
        <xsl:if test="position() > 1">,#</xsl:if>
        <xsl:value-of select="concat(./ns1:City,',',./ns1:State)"/>
    </xsl:for-each>
</xsl:variable>

Upvotes: 1

Related Questions