How to Iterate

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf How to Iterate

  • Creator
    Topic
  • #55423
    Layale Zakhour
    Participant

      Hi Jim,

      I’m struggling with creating an XML file  according to the format below. The source is a simple file which contains Category list and the items. The source is a database table: Items which list items per category. How do I generate the XML below? For each category, I need to list the items within the list.  

      1-       The source is a database table:

      ItemID, CategoryID, ItemDesc

      1,1,’Printer’

      2,1,’Scanner’

      3,2,’Laptop’

      4,2,’Desk’

      5,2,’Chair’

      2-       The target is an XML file which should be formatted based on the below:

       Printer

       Scanner

       Laptop

       Desk

       Chair

      Just give me hints please and I’ll be grateful.

    Viewing 7 reply threads
    • Author
      Replies
      • #85272
        Charlie Bursell
        Participant

          I’m not Jim but it seems to me if you want to do this in Xlate you will have to define a schema for the XML layout.

          If it were me, and it is not, rather than creating a schema for something this simple I would just do it in Tcl

        • #85273
          Layale Zakhour
          Participant

            Charlie Bursell wrote:

            I’m not Jim but it seems to me if you want to do this in Xlate you will have to define a schema for the XML layout.

            If it were me, and it is not, rather than creating a schema for something this simple I would just do it in Tcl

            Thanks Charlie. I’m keeping the tcl code as my last option. I’m hopeless on Cloverleaf but I still expect the tool to have the capabilities to translate the message without writing code  ðŸ˜•  

            I prepared an XML schema but let’s say I have CategoryID = 1 which contains 2 items, I could not produce the iteration below:

            Chair

            Desk

            I tried to use a database lookup table which returns the 2 items for CategoryId=1, but the table returns a tcl list.

          • #85274
            Jim Kosloskey
            Participant

              Layale,

              I have not used the DB Lookup but the doc indicates multiple fields returned will be returned as a comma separated list.

              You cannot ITERATE over this list natively as far as I know.

              In your case if you know the returned list will always be comprised of a fixed set of elements, you can use thee STRING Action (xlateStrSplit Function) to split what is returned into as many destinations as you need (or temp variables).

              You just need to be sure the actual data does not contain a comma.

              If you had the potential of a variable number of fields being returned then some Tcl will be required.

              When I have the situation where I have a string which could have any number of elements in a separated list, I have a generic Tcl proc which converts that list to a true Tcl list.

              Then I use the List ITERATE along with another generic proc I have to pop one element at a time from the produced true Tcl list. Using a technique to control the ITERATE I stay in that ITERATE until the list is empty.

              Handling of the instance of a variable number of elements requires more than just the cursory outline I gave above but the above is the gist.

              email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 60 years IT – old fart.

            • #85275
              Layale Zakhour
              Participant

                Hi Jim,

                Thank you for your response.

                Quote:

                When I have the situation where I have a string which could have any number of elements in a separated list, I have a generic Tcl proc which converts that list to a true Tcl list.

                Then I use the List ITERATE along with another generic proc I have to pop one element at a time from the produced true Tcl list. Using a technique to control the ITERATE I stay in that ITERATE until the list is empty.

                Do you mind sharing the Tcl proc that converts a list to a true Tcl list? Also do you mind sharing a screenshot on how to Iterate on a list? I’m still a newbie.

                Thanks a lot.

              • #85276
                Jim Kosloskey
                Participant

                  email me (my email is at the bottom of this post) and I will send you the proc.

                  email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 60 years IT – old fart.

                • #85277
                  Layale Zakhour
                  Participant

                    Jim Kosloskey wrote:

                    email me (my email is at the bottom of this post) and I will send you the proc.

                    Hi Jim,

                    I sent you an email. Awaiting your response. Thank you for your support!

                  • #85278
                    Jim Kosloskey
                    Participant

                      I responded to your email – I will resend.

                      Check your SPAM or Junk. Since it had attachments or maybe it failed on my email address inside your email service. I did not receive any notification of kick back on my original send.

                      I did a resend.

                      Let me know if you locate it.

                      email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 60 years IT – old fart.

                    • #85279
                      Layale Zakhour
                      Participant

                        Well received! Thanks a lot Jim!! Found it in spam folder.

                    Viewing 7 reply threads
                    • The forum ‘Cloverleaf’ is closed to new topics and replies.