XSLT apply Recursive function to filter out the data











up vote
0
down vote

favorite












We have some XML coming from a downstream system and we need to parse
it using XSLT to extract the information from it.
The input XML contains people information in it.
The output XML should contain the hierarchy among them (e.g: parents and children)



The input xml is as follows:



<person parent="null">
<name>ABC</name>
</person>
<person>
<name>child1</name>
<parent>ABC</parent>
</person>
<person>
<name>child2</name>
<parent>ABC</parent>
</person>
<person>
<name>child1.1</name>
<parent>child1</parent>
</person>
...


The output xml is:



<parent>
<name>ABC</name>
<childern>
<name>Child1</name>
<childern>
<name>Child 1.1</name>
</children>
<childern>
<name>Child 1.2</name>
</children>
...
</children>
<childern>
<name>Child2</name>
</children>
</parent>


So as it is obvious from the data that the hierarchy could be continuous so it means we need a recursive
way to handle it.
I have tried it using simple loops but couldn't get what I am hoping for.



How can I make a recursive function for it?










share|improve this question






















  • Declare a key <xsl:key name="children" match="person" use="parent"/>, then start processing person[@parent = 'null'] and process key('children', name) to recurse. You don't need a function for that, templates can be recursive simply by doing apply-templates.
    – Martin Honnen
    Nov 20 at 15:30















up vote
0
down vote

favorite












We have some XML coming from a downstream system and we need to parse
it using XSLT to extract the information from it.
The input XML contains people information in it.
The output XML should contain the hierarchy among them (e.g: parents and children)



The input xml is as follows:



<person parent="null">
<name>ABC</name>
</person>
<person>
<name>child1</name>
<parent>ABC</parent>
</person>
<person>
<name>child2</name>
<parent>ABC</parent>
</person>
<person>
<name>child1.1</name>
<parent>child1</parent>
</person>
...


The output xml is:



<parent>
<name>ABC</name>
<childern>
<name>Child1</name>
<childern>
<name>Child 1.1</name>
</children>
<childern>
<name>Child 1.2</name>
</children>
...
</children>
<childern>
<name>Child2</name>
</children>
</parent>


So as it is obvious from the data that the hierarchy could be continuous so it means we need a recursive
way to handle it.
I have tried it using simple loops but couldn't get what I am hoping for.



How can I make a recursive function for it?










share|improve this question






















  • Declare a key <xsl:key name="children" match="person" use="parent"/>, then start processing person[@parent = 'null'] and process key('children', name) to recurse. You don't need a function for that, templates can be recursive simply by doing apply-templates.
    – Martin Honnen
    Nov 20 at 15:30













up vote
0
down vote

favorite









up vote
0
down vote

favorite











We have some XML coming from a downstream system and we need to parse
it using XSLT to extract the information from it.
The input XML contains people information in it.
The output XML should contain the hierarchy among them (e.g: parents and children)



The input xml is as follows:



<person parent="null">
<name>ABC</name>
</person>
<person>
<name>child1</name>
<parent>ABC</parent>
</person>
<person>
<name>child2</name>
<parent>ABC</parent>
</person>
<person>
<name>child1.1</name>
<parent>child1</parent>
</person>
...


The output xml is:



<parent>
<name>ABC</name>
<childern>
<name>Child1</name>
<childern>
<name>Child 1.1</name>
</children>
<childern>
<name>Child 1.2</name>
</children>
...
</children>
<childern>
<name>Child2</name>
</children>
</parent>


So as it is obvious from the data that the hierarchy could be continuous so it means we need a recursive
way to handle it.
I have tried it using simple loops but couldn't get what I am hoping for.



How can I make a recursive function for it?










share|improve this question













We have some XML coming from a downstream system and we need to parse
it using XSLT to extract the information from it.
The input XML contains people information in it.
The output XML should contain the hierarchy among them (e.g: parents and children)



The input xml is as follows:



<person parent="null">
<name>ABC</name>
</person>
<person>
<name>child1</name>
<parent>ABC</parent>
</person>
<person>
<name>child2</name>
<parent>ABC</parent>
</person>
<person>
<name>child1.1</name>
<parent>child1</parent>
</person>
...


The output xml is:



<parent>
<name>ABC</name>
<childern>
<name>Child1</name>
<childern>
<name>Child 1.1</name>
</children>
<childern>
<name>Child 1.2</name>
</children>
...
</children>
<childern>
<name>Child2</name>
</children>
</parent>


So as it is obvious from the data that the hierarchy could be continuous so it means we need a recursive
way to handle it.
I have tried it using simple loops but couldn't get what I am hoping for.



How can I make a recursive function for it?







xml xslt wso2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 14:48









omer khalid

430530




430530












  • Declare a key <xsl:key name="children" match="person" use="parent"/>, then start processing person[@parent = 'null'] and process key('children', name) to recurse. You don't need a function for that, templates can be recursive simply by doing apply-templates.
    – Martin Honnen
    Nov 20 at 15:30


















  • Declare a key <xsl:key name="children" match="person" use="parent"/>, then start processing person[@parent = 'null'] and process key('children', name) to recurse. You don't need a function for that, templates can be recursive simply by doing apply-templates.
    – Martin Honnen
    Nov 20 at 15:30
















Declare a key <xsl:key name="children" match="person" use="parent"/>, then start processing person[@parent = 'null'] and process key('children', name) to recurse. You don't need a function for that, templates can be recursive simply by doing apply-templates.
– Martin Honnen
Nov 20 at 15:30




Declare a key <xsl:key name="children" match="person" use="parent"/>, then start processing person[@parent = 'null'] and process key('children', name) to recurse. You don't need a function for that, templates can be recursive simply by doing apply-templates.
– Martin Honnen
Nov 20 at 15:30

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395571%2fxslt-apply-recursive-function-to-filter-out-the-data%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395571%2fxslt-apply-recursive-function-to-filter-out-the-data%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen