• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XSL to check for tag existence and add in doesn't exist along with namespace

 
Greenhorn
Posts: 10
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to check for existence of a tag in request, till this point its done, after that if that tag doesn't exist i need to add the same.

My XSLT looks like

My XML look like


Any sort of help is highly appreciated.
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[0] I don't think abstracting the criteria to being the existence of a tag of local-name 'MyTag" at the level of depth to the 5th is a realistic abstraction. It can be done (see [2]), but it would give most probably wrong outcome than the right in most case except a very narrow scope of the incoming xml document.

[1] I advance that a more realistic criterion would be starting from knowing the specific namespace uri (http://my.com) and that the container node having the local-name header in that namespace. From thereon, check if there exists the tag MyTag of the same namespace as a child. If it does not exist, add that one to it. In that case, this is how the xsl document looks like. (prefix x tries to highlight the arbitrariness of it as long as it points to the right namespace.)

[2] If you insist on your set of criteria, it would look like this. (But again, it would be more self-misleading than really helpful, despite it contains plenty of illustrative and useful elements of construction.)
 
reply
    Bookmark Topic Watch Topic
  • New Topic