I'm using XSLT 1.0 to transform an XML document to a different schema of XML. The source document may or may not have elements depending on the source database it is built from.
EG
<Patients>
<Patient id="1019">
<Surname>Acqua</Surname>
<Forenames>Matthew James</Forenames>
<VoicePhone>0111 222 33333</VoicePhone>
</Patient>
<Patient id="1020">
<Surname>Red</Surname>
<Forenames>James Alan</Forenames>
</Patient>
</Patients>
The resulting output after transforming via XML will have empty elements in it because the VoicePhone in the second patient doesn't exist (rather than exist but is empty).
The XSLT is along these lines:
<xsl:template match="//Patients/Patient">
<PatientRxs>
<PatientInfo>
<FirstName>
<xsl:value-of select="Forenames"/>
</FirstName>
<Telephone>
<xsl:value-of select="VoicePhone"/>
</Telephone>
</PatientInfo>
</PatientRxs>
</xsl:template>
And I end up with:
<PatientRxs>
<PatientInfo>
<FirstName>Matthew James</FirstName>
<Telephone>0111 222 33333</Telephone>
</PatientInfo>
</PatientRxs>
<PatientRxs>
<PatientInfo>
<FirstName>James Alan</FirstName>
<Telephone/>
</PatientInfo>
</PatientRxs>
Where I actually want:
<PatientRxs>
<PatientInfo>
<FirstName>Matthew James</FirstName>
<Telephone>0111 222 33333</Telephone>
</PatientInfo>
</PatientRxs>
<PatientRxs>
<PatientInfo>
<FirstName>James Alan</FirstName>
</PatientInfo>
</PatientRxs>
Although I could test if the value exists this is just 1 of hundreds of elements that could potentially not exist in the source document and would like to avoid having an XSLT sheet testing every single one of them