Given that your XSLT code doesn't actually work, it's difficult to use it to reverse engineer your requirements. Apart from anything else, it uses variables like $attname and $root_pos which you haven't explained. So let's ignore it and concentrate on your English statement of requirements:
"I have to create the two above mentioned date attributes, only if the input xml contains any/all of the four supplier cost fields and the date fields should get created only once if any/all of the four supplier cost fields are present in the input. I tried the above xsl logic, but it fails if all the four or some of the supplier cost fields are present in the input, the output has repeating date fields coz of the obvious reason behind the logic applied above."
Now, I'm not sure what the "two above mentioned date attributes are", and I don't know what "any/all" is supposed to mean - does it mean "any", or "all" - it can't mean both! However, one thing is clear, and that's that you don't need a for-each in the solution. You want something much closer to the logic of your requirements statement: if (the relevant fields exist) then (create the required attributes)".
Showing your required output might be useful.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|