• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

xslt recursive loop

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an input xml document out of which most of the tags are to be copied over to the output xml as such. At some places(Xpaths), there is a need to make some modifications / add additional entries.
This is done using a recursive loop until the matching template is found for the Xpath. I am not sure if this is an effective way of doing this. Do you have any better suggestions/solution? How are these things generally handled? Any pointers/link would really help.
I have pasted a gist of the xsl below,



Thanks...
 
Marshal
Posts: 26106
72
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You took an identity transformation and added a new template to make specific changes, right? That's a perfectly reasonable way to do things.
 
James Kesari
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I applied the modifications on the new template. But my concern was on the recursive looping.
The recursive loop runs through to find a matching template and if it finds one it applies the template, else it just copies over(starting from the leaf node).
I was thinking of a better way for running the recursive loop.
Say, if the program realizes the parent node it is trying to match doesn't match with any of the templates then it should just copy it over and should not even recurse further.
If it finds one, then it should go to the child node and find for the next match.
This might significantly reduce time. But I was looking for a better way of accomplishing this.
For eg.,


If I have to modify <d> node, then the loop should not even go inside <a>. It should just copy <a>.
It should go inside a node only if it realizes a node under it needs to be modified.

Do you have any suggestions?
 
Paul Clapham
Marshal
Posts: 26106
72
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My suggestion: if it ain't broke, don't fix it.

Of course if you have some spare time and want to mess about with the identity template, by all means go ahead. But pretty much everything you said in that last post doesn't apply. For example:

if the program realizes the parent node it is trying to match doesn't match with any of the templates

The identity program's templates match every single node. And:

the loop should not even go inside <a>. It should just copy <a>

Copying an <a> element also involves copying its children (what you call "going inside"). The recursive template does this automatically.

But as I said, messing about with that template could be a useful learning experience.
 
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic