Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

best way to handle optional elements in XSLT

659283Oct 2 2008 — edited Feb 27 2020
Hi All,

I'v wondering if there are any better ways to handle optional fields in XSLT.

For example if my Person Type has 5 fields and 3 of them are optional:

<xs:complexType name="PersonType">
<xs:element name="PersonID" min="1"/>
<xs:element name="PIN" min="1"/>
<xs:element name="FirstName" min="0"/>
<xs:element name="MiddleName" min="0"/>
<xs:element name="LastName" min="0"/>
</xs:complexType>

In my xslt file, if I do somthing like:

<Person>
<FirstName>
<xsl:value-of select="PersonType/FirstName"/>
</FirstName>
</Person>

I might get an empty FirstName element in my output xml file. (like <FirstName/>) This has caused some very weired behavour with Oracle v2 parser because optional means the node may not be present in the xml not the node is there but empty.

The only way I can think of solving this is to put <xsl:if test> around every single optional element to test if it exist in the source file. If it does then generate the element in the destination file. But in this way, if the source file is very complicated, then you would have to wrap each element with a <xsl:test> which is very ugly to me.

Do anyone know if there is a more generic way that we can solve this issue?

Thanks,

Larry
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 17 2010
Added on Oct 2 2008
6 comments
4,831 views