Add attribute xsl:nil=true on empty elements using XSLT
- Joel Lipman
- XML Stylesheet Language Transformations
- Hits: 12719
An article on how to declare an XML element as NULL using the attribute "xsi:nil". I'm going to use a very short example by providing a blank date of birth value:
copyraw
-- What I have: <DATE_OF_BIRTH /> <DATE_OF_BIRTH_EUROPEANFORMAT>//</DATE_OF_BIRTH_EUROPEANFORMAT> -- What I want: <DATE_OF_BIRTH xsi:nil="true" /> <DATE_OF_BIRTH_EUROPEANFORMAT xsi:nil="true" />
- -- What I have:
- <DATE_OF_BIRTH />
- <DATE_OF_BIRTH_EUROPEANFORMAT>>//</DATE_OF_BIRTH_EUROPEANFORMAT>
- -- What I want:
- <DATE_OF_BIRTH xsi:nil="true" />
- <DATE_OF_BIRTH_EUROPEANFORMAT xsi:nil="true" />
Why?
Outputting from SITS:Vision to our staging environment, the application would only output blank values using single tags so we had to find a place to introduce it. On strings this has little worth, but on dates which could be NULL, this was necessary (unless we interpreted dates as strings which we don't want to do):
Category: XML Stylesheet Language Transformations :: Article: 578