none
Set Default value in elements with looping record RRS feed

  • Question

  • My input schema instance is as follows:

    <ns0:Root xmlns:ns0="http://LogicalFunctoid.EmployeeSchema2">
      <PeopleSoft>
        <Employees>
          <Employee>
            <ID>13</ID>
            <Name>Ellie Goudling</Name>
            <Salary>300000</Salary>
          </Employee>
     <Employee>
            <ID>123</ID>
            <Name>Prakash Sajwan</Name>
            <Salary>100000</Salary>
          </Employee>
        </Employees>
      </PeopleSoft>
      <SAP>
       <Employees>
          <Employee>
            <ID>153</ID>
            <Name>Ravi Goudling</Name>
            <Salary>300000</Salary>
          </Employee>
     <Employee>
            <ID>173</ID>
            <Name>Pradeep Sajwan</Name>
            <Salary>100000</Salary>
          </Employee>
       </Employees>
      </SAP>
    </ns0:Root>

    I want the following output instance file:

    <ns0:Records xmlns:ns0="http://LogicalFunctoid.EmployeeOutputSchema">
    <Record>
      <ID>13</ID> 
      <Name>Ellie Goudling</Name> 
      <Salary>300000</Salary> 
      <Region>Oracle</Region> 
      </Record>
     <Record>
      <ID>123</ID> 
      <Name>Prakash Sajwan</Name> 
      <Salary>100000</Salary> 
      <Region>Oracle</Region> 
      </Record>
     <Record>
      <ID>153</ID> 
      <Name>Ravi Goudling</Name> 
      <Salary>300000</Salary> 
      <Region>SAP</Region> 
      </Record>
     <Record>
      <ID>173</ID> 
      <Name>Pradeep Sajwan</Name> 
      <Salary>100000</Salary> 
      <Region>SAP</Region> 
      </Record>
      </ns0:Records>

    I apply the looping functoid as follows:


    I am getting the following o/p:

    <ns0:Records xmlns:ns0="http://LogicalFunctoid.EmployeeOutputSchema">

    <Record>
      <ID>13</ID> 
      <Name>Ellie Goudling</Name> 
      <Salary>300000</Salary> 
      <Region></Region> 
      </Record>
    <Record>
      <ID>123</ID> 
      <Name>Prakash Sajwan</Name> 
      <Salary>100000</Salary> 
      <Region></Region> 
      </Record>
    <Record>
      <ID>153</ID> 
      <Name>Ravi Goudling</Name> 
      <Salary>300000</Salary> 
      <Region></Region> 
      </Record>
     <Record>
      <ID>173</ID> 
      <Name>Pradeep Sajwan</Name> 
      <Salary>100000</Salary> 
      <Region></Region> 
      </Record>
      </ns0:Records>

    But its not the desire o/p.

    How can I get the appropriate value in Region element ?

    I got my desire o/p through custom xslt but I want my desire o/p through functoid.

    Any kind of help would be appreciated.


    Prakash


    • Edited by Shivay_ Wednesday, June 10, 2015 6:48 AM
    Wednesday, June 10, 2015 6:47 AM

Answers

  • Finally,I got the solution as below :

    And in script functoid,I write the following code:

    <xsl:if test="ancestor::PeopleSoft">
     <Region>
    <xsl:text>oracle</xsl:text>
    </Region>
    </xsl:if>

     <xsl:if test="name(../..)='SAP'">
                 <Region>
                     SAP
                 </Region>
         </xsl:if>

    And I got my desire output.

    :)


    Prakash

    • Marked as answer by Shivay_ Monday, June 15, 2015 2:07 PM
    Monday, June 15, 2015 2:06 PM

All replies

  • well I think you can use a scripting functiod.

    Take a scripting functiod and set it to Inline xslt.

    link both employee records to scripting funtiods and link output to Region node.

    and inside use the following approach something like below 

    <xsl:if test(../../Employee='PeopleSoft') <Region> Oracle </Region>

    </xsl:if>

    similarly test for SAP

    <../../Employee='SAP' <Region> SAP</Region>


    I have not tested it though.


    Please mark the post as answer if this answers your question. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

    Wednesday, June 10, 2015 7:42 AM
  • Hi Parkash,

    You could use a simple xslt template.

      <xsl:template name="Records">
        <ns0:Records xmlns:ns0="http://LogicalFunctoid.EmployeeOutputSchema">
          <!-- Loop PeopleSoft-->
          <xsl:for-each select="/*[local-name()='Root' and namespace-uri()='http://LogicalFunctoid.EmployeeSchema2']/*[local-name()='PeopleSoft']/*[local-name()='Employees']/*[local-name()='Employee']">
            <Record>
              <ID>
                <xsl:value-of select="./*[local-name()='ID']"/>
              </ID>
              <Name>
                <xsl:value-of select="./*[local-name()='Name']"/>
              </Name>
              <Salary>
                <xsl:value-of select="./*[local-name()='Salary']"/>
              </Salary>
              <Region>
                <xsl:text>Oracle</xsl:text>
              </Region>
            </Record>
          </xsl:for-each>
    
          <!-- Loop SAP-->
          <xsl:for-each select="/*[local-name()='Root' and namespace-uri()='http://LogicalFunctoid.EmployeeSchema2']/*[local-name()='SAP']/*[local-name()='Employees']/*[local-name()='Employee']">
            <Record>
              <ID>
                <xsl:value-of select="./*[local-name()='ID']"/>
              </ID>
              <Name>
                <xsl:value-of select="./*[local-name()='Name']"/>
              </Name>
              <Salary>
                <xsl:value-of select="./*[local-name()='Salary']"/>
              </Salary>
              <Region>
                <xsl:text>SAP</xsl:text>
              </Region>
            </Record>
          </xsl:for-each>
        </ns0:Records>
      </xsl:template>

    Best regards 

    Rasmus Jaeger

    Wednesday, June 10, 2015 8:26 AM
  • Should be very simple.

    1. Link PeopleSoft|SAP|Oracle node to the Region node.
    2. Click the link.
    3. Set the Source Links property to Copy name.

    You may have to also link PeopleSoft|SAP|Oracle to the Looping Functoid as well.

    Wednesday, June 10, 2015 11:08 AM
    Moderator
  • You are right John,

    however for the records under PeopleSoft in the source, he want the destination Region field to output as "Oracle"

    and for the records under SAP in the source, he want the destination Region field output as "SAP"

    there is no "Oracle" node in the source.

    (apologies if i misunderstood)


    Please mark the post as answer if this answers your question. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

    Wednesday, June 10, 2015 12:33 PM
  • Sure, but for that it's just a Script Functoid with a switch statement to return the correct value.
    Wednesday, June 10, 2015 4:02 PM
    Moderator
  • Hii John.

    I did what you suggested as follows:

    1. Link PeopleSoft|SAP|Oracle node to the Region node.
    2. Click the link.
    3. Set the Source Links property to Copy name.

    I also link PeopleSoft|SAP to the Looping Functoid .

    Here is the screenshot for your reference :

    

    This is my input:

    <ns0:Root xmlns:ns0="http://LogicalFunctoid.EmployeeSchema2">
      <PeopleSoft>
        <Employees>
          <Employee>
            <ID>13</ID>
            <Name>Ellie Goudling</Name>
            <Salary>300000</Salary>
          </Employee>
    </Employees>
      </PeopleSoft>
      <SAP>
       <Employees>
          <Employee>
            <ID>173</ID>
            <Name>Pradeep Sajwan</Name>
            <Salary>100000</Salary>
          </Employee>
       </Employees>
      </SAP>
    </ns0:Root>

    And I am getting the following o/p:

    <ns0:Records xmlns:ns0="http://LogicalFunctoid.EmployeeOutputSchema">
    <Record>
      <ID>13</ID> 
      <Name>Ellie Goudling</Name> 
      <Salary>300000</Salary> 
      <Region>PeopleSoft</Region> 
      </Record>
     <Record>
      <ID>173</ID> 
      <Name>Pradeep Sajwan</Name> 
      <Salary>100000</Salary> 
      <Region>SAP</Region> 
      </Record>
     <Record>
      <ID>13</ID> 
      <Name>Ellie Goudling</Name> 
      <Salary>300000</Salary> 
      <Region>PeopleSoft</Region> 
      </Record>
     <Record>
      <ID>173</ID> 
      <Name>Pradeep Sajwan</Name> 
      <Salary>100000</Salary> 
      <Region>SAP</Region> 
      </Record>
      </ns0:Records>

    As you can see in the o/p, the value of region is correct but I got four records while in my input there are two records.

    I think, I got the extra record because I connected the link PeopleSoft|SAP to the Looping Functoid.

    But when I did not connected the link PeopleSoft|SAP to the Looping Functoid , I got the following result: 

     <ns0:Records xmlns:ns0="http://LogicalFunctoid.EmployeeOutputSchema">
    <Record>
      <ID>13</ID> 
      <Name>Ellie Goudling</Name> 
      <Salary>300000</Salary> 
      <Region>PeopleSoft</Region> 
      <Region>SAP</Region> 
      </Record>
     <Record>
      <ID>173</ID> 
      <Name>Pradeep Sajwan</Name> 
      <Salary>100000</Salary> 
      <Region>PeopleSoft</Region> 
      <Region>SAP</Region> 
      </Record>
      </ns0:Records>

    Here,no of records are correct but value of region is not correct.

    So would you like to suggest me how can I get my desire o/p.


    Prakash


    • Edited by Shivay_ Friday, June 12, 2015 6:52 AM
    Friday, June 12, 2015 6:51 AM
  • Hi Prakash,

    Something we cant able to achieve some functionality using functoid,  so we have another option of custom xslt, go ahead with the custom xslt to make life easier. Find below the sample I used for creating the output as expected.

    If the SAP/Peoplesoft is coming from a field we can control, now we don't have the control to check when we hav a loop. SO go ahead with xslt.

      <?xml version="1.0" encoding="UTF-16" ?> 
    - <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var" version="1.0">
      <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" /> 
    - <xsl:template match="/">
      <xsl:apply-templates select="/Root" /> 
      </xsl:template>
    - <xsl:template match="/Root">
    - <Records>
    - <xsl:for-each select="SAP/Employees/Employee">
    - <Record>
    - <ID>
      <xsl:value-of select="ID/text()" /> 
      </ID>
    - <Name>
      <xsl:value-of select="Name/text()" /> 
      </Name>
    - <Salary>
      <xsl:value-of select="Salary/text()" /> 
      </Salary>
      <Region>SAP</Region> 
      </Record>
      </xsl:for-each>
    - <xsl:for-each select="PeopleSoft/Employees/Employee">
    - <Record>
    - <ID>
      <xsl:value-of select="ID/text()" /> 
      </ID>
    - <Name>
      <xsl:value-of select="Name/text()" /> 
      </Name>
    - <Salary>
      <xsl:value-of select="Salary/text()" /> 
      </Salary>
      <Region>PeopleSoft</Region> 
      </Record>
      </xsl:for-each>
      </Records>
      </xsl:template>
      </xsl:stylesheet>


    Regards, Aboorva Raja R Please remember to mark the replies as answers if they help and unmark them if they provide no help.





    Friday, June 12, 2015 9:33 AM
  • Hi Ramar,

    Thanks for your reply,but  I already mentioned in my question that I have done it through custom xslt and I want to done it through functoid if it possible.


    Prakash

    Friday, June 12, 2015 10:22 AM
  • Hi Prakash,

    I have mentioned in my comments, it is not possible to achieve this thro functoids.

    If the SAP/Peoplesoft values coming from a field element we can achieve this scenario, now in functoid we cant able to identify the record node name to loop based on the record name. In xslt you can able to identify the node name.

    So we cant able to achieve using functoid.



    Regards, Aboorva Raja R Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 12, 2015 1:23 PM
  • Finally,I got the solution as below :

    And in script functoid,I write the following code:

    <xsl:if test="ancestor::PeopleSoft">
     <Region>
    <xsl:text>oracle</xsl:text>
    </Region>
    </xsl:if>

     <xsl:if test="name(../..)='SAP'">
                 <Region>
                     SAP
                 </Region>
         </xsl:if>

    And I got my desire output.

    :)


    Prakash

    • Marked as answer by Shivay_ Monday, June 15, 2015 2:07 PM
    Monday, June 15, 2015 2:06 PM