Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Calling a template recursively??

Calling a template recursively??

Scheduled Pinned Locked Moved XML / XSL
xmltutorialquestion
22 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rocky
    wrote on last edited by
    #1

    Hello everyone, well I want to make this one as simple as I can. I have an XML inwhich you can get nodes in this type of format .... Now what I'm trying to do is to traverse it recursively using just a single template to tranverse both the /LOG/CallSequence/Call and any CallSequence/Call Elements that occur inside it. So can anyone plz give me an idea of how to do this. I have made a template that traverses the outer part but i dont know how to reach the inside CallSequence/Call part???!!! Thanks in advance! Rocky You can't climb up a ladder with your hands in your pockets.

    G 1 Reply Last reply
    0
    • R Rocky

      Hello everyone, well I want to make this one as simple as I can. I have an XML inwhich you can get nodes in this type of format .... Now what I'm trying to do is to traverse it recursively using just a single template to tranverse both the /LOG/CallSequence/Call and any CallSequence/Call Elements that occur inside it. So can anyone plz give me an idea of how to do this. I have made a template that traverses the outer part but i dont know how to reach the inside CallSequence/Call part???!!! Thanks in advance! Rocky You can't climb up a ladder with your hands in your pockets.

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      Here is an example: Call Sequence "We make a living by what we get, we make a life by what we give." --Winston Churchill

      R 2 Replies Last reply
      0
      • G George L Jackson

        Here is an example: Call Sequence "We make a living by what we get, we make a life by what we give." --Winston Churchill

        R Offline
        R Offline
        Rocky
        wrote on last edited by
        #3

        That looks preetu helpful but the problem is that the xsl I'm working on is very large and accessing the CallSequence/Call is used at two places. So I wanted to use the same template for both. that is for outer as well the inner occurence. The XML can contain any number of call sequences within a call as u know a method can call another method and that can call yet another one so what i'm trying to do is to develop a template which i can call by passing it the set of nodes. Then it should display it. by the way if we use xsl:template match="CallSequence"... is it able to get all the CallSequence nodes as we traverse down the tree??

        Rocky You can't climb up a ladder with your hands in your pockets.

        1 Reply Last reply
        0
        • G George L Jackson

          Here is an example: Call Sequence "We make a living by what we get, we make a life by what we give." --Winston Churchill

          R Offline
          R Offline
          Rocky
          wrote on last edited by
          #4

          its giving an error The XSL processor stack has overflowed - probable cause is infinite template recursion what should be the termination condition in this?

          Rocky You can't climb up a ladder with your hands in your pockets.

          G 1 Reply Last reply
          0
          • R Rocky

            its giving an error The XSL processor stack has overflowed - probable cause is infinite template recursion what should be the termination condition in this?

            Rocky You can't climb up a ladder with your hands in your pockets.

            G Offline
            G Offline
            George L Jackson
            wrote on last edited by
            #5

            is the recursive call and will be called if "CallSequence" is a child of itself at any point. If you call this more than once within your xsl:for-each loop, you will run out of stack. Also, it should return once it does not find another child "CallSequence"; however, if your xsl:for-each does not account for a recursive call, it will cause an out-of stack error also. It is very hard to troubleshoot a large template with nested xsl:for-each loops. I advise you to break up your code into several templates. XSLT is functional in nature and you should keep nested levels of xsl:for-each to a minimum. "We make a living by what we get, we make a life by what we give." --Winston Churchill

            R 3 Replies Last reply
            0
            • G George L Jackson

              is the recursive call and will be called if "CallSequence" is a child of itself at any point. If you call this more than once within your xsl:for-each loop, you will run out of stack. Also, it should return once it does not find another child "CallSequence"; however, if your xsl:for-each does not account for a recursive call, it will cause an out-of stack error also. It is very hard to troubleshoot a large template with nested xsl:for-each loops. I advise you to break up your code into several templates. XSLT is functional in nature and you should keep nested levels of xsl:for-each to a minimum. "We make a living by what we get, we make a life by what we give." --Winston Churchill

              R Offline
              R Offline
              Rocky
              wrote on last edited by
              #6

              OK that looks helpful to me! Please tell what this statement is doing in the example code you've given, When I changed the . to CallSequence it doesnt show anything (atleast the error is gone) but when i put this as you have given it runs out of stack. right now I'm just trying to run your code in order to make an understanding of the template I wanna make at the moment. After I'm done with this I'll concentrate on embedding it in the whole this as a sepearte function like you said Rocky You can't climb up a ladder with your hands in your pockets.

              G 1 Reply Last reply
              0
              • G George L Jackson

                is the recursive call and will be called if "CallSequence" is a child of itself at any point. If you call this more than once within your xsl:for-each loop, you will run out of stack. Also, it should return once it does not find another child "CallSequence"; however, if your xsl:for-each does not account for a recursive call, it will cause an out-of stack error also. It is very hard to troubleshoot a large template with nested xsl:for-each loops. I advise you to break up your code into several templates. XSLT is functional in nature and you should keep nested levels of xsl:for-each to a minimum. "We make a living by what we get, we make a life by what we give." --Winston Churchill

                R Offline
                R Offline
                Rocky
                wrote on last edited by
                #7

                well now I've changed the to and its showing the output BUT... as I was thinking... the Call Node that has other CallSequence nodes is comming out at the end bcz of the stack. Actually the calling function should come at the top rather than at the bottom. Right now I'm thinking abt another way around. How abt if I use a template to display the Nodes inside a Call and if there is yet another CallSequence I call that template again (using Call-template) with the new Node Set. Rocky You can't climb up a ladder with your hands in your pockets.

                1 Reply Last reply
                0
                • G George L Jackson

                  is the recursive call and will be called if "CallSequence" is a child of itself at any point. If you call this more than once within your xsl:for-each loop, you will run out of stack. Also, it should return once it does not find another child "CallSequence"; however, if your xsl:for-each does not account for a recursive call, it will cause an out-of stack error also. It is very hard to troubleshoot a large template with nested xsl:for-each loops. I advise you to break up your code into several templates. XSLT is functional in nature and you should keep nested levels of xsl:for-each to a minimum. "We make a living by what we get, we make a life by what we give." --Winston Churchill

                  R Offline
                  R Offline
                  Rocky
                  wrote on last edited by
                  #8

                  Call to

                  Object Type

                  Object Name

                  Interface Name

                  Return Code

                  Inputs

                  Inputs

                  Output----------------- I've almost done it!! the calling doesnt go to the third level so I call it this way...

                  G 1 Reply Last reply
                  0
                  • R Rocky

                    OK that looks helpful to me! Please tell what this statement is doing in the example code you've given, When I changed the . to CallSequence it doesnt show anything (atleast the error is gone) but when i put this as you have given it runs out of stack. right now I'm just trying to run your code in order to make an understanding of the template I wanna make at the moment. After I'm done with this I'll concentrate on embedding it in the whole this as a sepearte function like you said Rocky You can't climb up a ladder with your hands in your pockets.

                    G Offline
                    G Offline
                    George L Jackson
                    wrote on last edited by
                    #9

                    Sorry, my mistake. The "." means current node. It should be "CallSequence".

                    "We make a living by what we get, we make a life by what we give." --Winston Churchill

                    1 Reply Last reply
                    0
                    • R Rocky

                      Call to

                      Object Type

                      Object Name

                      Interface Name

                      Return Code

                      Inputs

                      Inputs

                      Output----------------- I've almost done it!! the calling doesnt go to the third level so I call it this way...

                      G Offline
                      G Offline
                      George L Jackson
                      wrote on last edited by
                      #10

                      You just have to remember that xsl:call-template works with the current node and doesn't change scope like xsl:apply-templates. Also, xsl:apply-templates has a mode attribute that is used to name it like xsl:call-templates and you can pass parameters to it also.

                      "We make a living by what we get, we make a life by what we give." --Winston Churchill

                      R 1 Reply Last reply
                      0
                      • G George L Jackson

                        You just have to remember that xsl:call-template works with the current node and doesn't change scope like xsl:apply-templates. Also, xsl:apply-templates has a mode attribute that is used to name it like xsl:call-templates and you can pass parameters to it also.

                        "We make a living by what we get, we make a life by what we give." --Winston Churchill

                        R Offline
                        R Offline
                        Rocky
                        wrote on last edited by
                        #11

                        wht does it mean when we say that call-template doesnt change scope? bcz after this statement the xsl:template gets called right? so we can change the scope inside the template right?

                        Rocky You can't climb up a ladder with your hands in your pockets.

                        G 1 Reply Last reply
                        0
                        • R Rocky

                          wht does it mean when we say that call-template doesnt change scope? bcz after this statement the xsl:template gets called right? so we can change the scope inside the template right?

                          Rocky You can't climb up a ladder with your hands in your pockets.

                          G Offline
                          G Offline
                          George L Jackson
                          wrote on last edited by
                          #12

                          xsl:call-template has is own "scope" as far as variable creation. But the scope of the current node and node-list is the same as its calling parent.

                          "We make a living by what we get, we make a life by what we give." --Winston Churchill

                          R 1 Reply Last reply
                          0
                          • G George L Jackson

                            xsl:call-template has is own "scope" as far as variable creation. But the scope of the current node and node-list is the same as its calling parent.

                            "We make a living by what we get, we make a life by what we give." --Winston Churchill

                            R Offline
                            R Offline
                            Rocky
                            wrote on last edited by
                            #13

                            OK! can u tel me how can we get the parent node of the current node. I was thinking that while traversing through the $nodeset I shoujld chk for the existance of another CallSequence Node and the call the same template again recursively. Rocky You can't climb up a ladder with your hands in your pockets.

                            G 1 Reply Last reply
                            0
                            • R Rocky

                              OK! can u tel me how can we get the parent node of the current node. I was thinking that while traversing through the $nodeset I shoujld chk for the existance of another CallSequence Node and the call the same template again recursively. Rocky You can't climb up a ladder with your hands in your pockets.

                              G Offline
                              G Offline
                              George L Jackson
                              wrote on last edited by
                              #14

                              It can be "parent::node()" or "parent::*". I think you can specifically check if the parent has a specific name by using "parent::CallSequence"!

                              "We make a living by what we get, we make a life by what we give." --Winston Churchill

                              R 3 Replies Last reply
                              0
                              • G George L Jackson

                                It can be "parent::node()" or "parent::*". I think you can specifically check if the parent has a specific name by using "parent::CallSequence"!

                                "We make a living by what we get, we make a life by what we give." --Winston Churchill

                                R Offline
                                R Offline
                                Rocky
                                wrote on last edited by
                                #15

                                I was thinking abt starting a new articles on this but then I changed my mind again... I'm back to the recursive solution again bcz the previous one wasn't showing the right sequence and this recursive one gets a nodeset missed when it starts recursion. I'm giving the template I made and the XML I'm using. Here comes the Template! Recursive Solution

                                Call to

                                Object Type

                                Object Name

                                Interface Name

                                Return Code

                                Inputs

                                1 Reply Last reply
                                0
                                • G George L Jackson

                                  It can be "parent::node()" or "parent::*". I think you can specifically check if the parent has a specific name by using "parent::CallSequence"!

                                  "We make a living by what we get, we make a life by what we give." --Winston Churchill

                                  R Offline
                                  R Offline
                                  Rocky
                                  wrote on last edited by
                                  #16

                                  I've found why this is missing the calling functions data As you can see this isthe basic model of recursion I'm using which was proposed by you previously. What happens is that that this condition in the choose-when actually doesnt consider whether there are some nodes above another CallSequence Clause. -------------- see this section of XML Unit ChemSepUO_382 ICapeUnit Calculate -------------- I've tried to change the conditions but its no help Rocky You can't climb up a ladder with your hands in your pockets.

                                  1 Reply Last reply
                                  0
                                  • G George L Jackson

                                    It can be "parent::node()" or "parent::*". I think you can specifically check if the parent has a specific name by using "parent::CallSequence"!

                                    "We make a living by what we get, we make a life by what we give." --Winston Churchill

                                    R Offline
                                    R Offline
                                    Rocky
                                    wrote on last edited by
                                    #17

                                    FINALLY !! I've DONE it... The EUREKA moment has come and I thought I should tell u first? Thanks a lot George... Its been a pleasure! "We make a living by what we get, we make a life by what we give." --Winston Churchill That's definately true!

                                    Rocky You can't climb up a ladder with your hands in your pockets.

                                    G 1 Reply Last reply
                                    0
                                    • R Rocky

                                      FINALLY !! I've DONE it... The EUREKA moment has come and I thought I should tell u first? Thanks a lot George... Its been a pleasure! "We make a living by what we get, we make a life by what we give." --Winston Churchill That's definately true!

                                      Rocky You can't climb up a ladder with your hands in your pockets.

                                      G Offline
                                      G Offline
                                      George L Jackson
                                      wrote on last edited by
                                      #18

                                      Congrats! :-D I bet you learned a lot about XSLT doing this exercise. Make sure you write down what you experienced for future reference.

                                      "We make a living by what we get, we make a life by what we give." --Winston Churchill

                                      R 2 Replies Last reply
                                      0
                                      • G George L Jackson

                                        Congrats! :-D I bet you learned a lot about XSLT doing this exercise. Make sure you write down what you experienced for future reference.

                                        "We make a living by what we get, we make a life by what we give." --Winston Churchill

                                        R Offline
                                        R Offline
                                        Rocky
                                        wrote on last edited by
                                        #19

                                        Yes. definately that was a really good one! I learned alot from that. I'll definately make some notes and save that work as well.:-D

                                        Rocky You can't climb up a ladder with your hands in your pockets.

                                        1 Reply Last reply
                                        0
                                        • G George L Jackson

                                          Congrats! :-D I bet you learned a lot about XSLT doing this exercise. Make sure you write down what you experienced for future reference.

                                          "We make a living by what we get, we make a life by what we give." --Winston Churchill

                                          R Offline
                                          R Offline
                                          Rocky
                                          wrote on last edited by
                                          #20

                                          hi how ru doing? Can u plz tell me how i can get the distint nodes in an XML. I've searched and found these two options distinct-nodes function for-each-group function and the distinct-values function but I havent been able to use them properly. They belong to XSLT 2.0 and well seems to me like somethings missing. Either the namespace or something? how should I declare it? and I've also visited the saxon website. What exactly do i need to download from there?? I'm confused ? thanks in advance

                                          Rocky You can't climb up a ladder with your hands in your pockets.

                                          G 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups