Is it possible to detect the presence of a (xml) tag using XSLT? -


I think to test the presence of a tag and create a new node according to the result.

This input is XML:

  & lt; Root & gt; & Lt; Tag1 & gt; NS & lt; / Tag1 & gt; & Lt; Tag2 id = "8" & gt; NS & lt; / Tag2 & gt; & Lt; Test & gt; & Lt; Other_tag> Text & lt; / Other_tag> & Lt; Main & gt; Y & lt; / Home & gt; & Lt; / Test & gt; & Lt; Test & gt; & Lt; Other_tag> Text & lt; / Other_tag> & Lt; / Test & gt; & Lt; / Root & gt;  

and the required output is XML:

  & lt; Root & gt; & Lt; Tag1 & gt; NS & lt; / Tag1 & gt; & Lt; Tag2 id = "8" & gt; NS & lt; / Tag2 & gt; & Lt; Test & gt; & Lt; Other_tag> Text & lt; / Other_tag> & Lt; Main_Tag & gt; Current & lt; / Main_Tag & gt; & Lt; / Test & gt; & Lt; Test & gt; & Lt; Other_tag> Text & lt; / Other_tag> & Lt; Main_Tag & gt; Absent & lt; / Main_Tag & gt; & Lt; / Test & gt; & Lt; / Root & gt;  

I have to check the value of tags, but this is something new to me.

I tried to use this template: (which is required)

   

I do not suggest that it is better - for this problem, maybe I Rubens describes Farias - but it shows another view of the problem that can be useful in more complex situations. I think the more logic I push into the template-mailing, turn out to be more flexible and extended my changes to be in the long run. Therefore, add this identity to the result:

  & lt; Xsl: template match = "test / main" & gt; & Lt; Main_Tag & gt; Current & lt; / Main_Tag & gt; & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "test [no (main)]" & gt; & Lt; XSL: Copy & gt; & Lt; Xsl: apply-select template = "node () | @ *" /> & Lt; Main_Tag & gt; Absent & lt; / Main_Tag & gt; & Lt; / XSL: Copy & gt; & Lt; / XSL: Copy & gt;  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -