I am new to XSLT I am trying to transform a name value pair to its corresponding XML. This feature is primarily used in case of special extensions to a standard. The file I want to transform is the following.
<ODEventNotificationExtraField>
<callCode>1</callCode>
<callbackType>All </callbackType>
<callbackEmail>me@mine.org </callbackEmail>
</ODEventNotificationExtraField>
to the following:
<?xml version="1.0" encoding="UTF-8"?>
<extensionList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ExtensionItems.xsd">
<extensionsItem>
<extName> callCode</extName>
<extValue>1</extValue>
<extType>integer</extType>
</extensionsItem>
<extensionsItem>
<extName>callbackType</extName>
<extValue>All</extValue>
<extType>string</extType>
</extensionsItem>
<extensionsItem>
<extName>callbackEmail</extName>
<extValue>me@mine.org</extValue>
<extType>string</extType>
</extensionsItem>
</extensionsList>
Based On the Field Name for example CallCode I will know it is of type integer( it needs to be hardcoded in xslt)
the xmlschema for the incoming data is defined as
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:simpleType name="CallbackType">
<xs:restriction base="xs:string">
<xs:enumeration value="Restoration"/>
<xs:enumeration value="Estimated"/>
<xs:enumeration value="All"/>
<xs:enumeration value="None"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="ODEventNotificationExtraField">
<xs:complexType>
<xs:sequence>
<xs:element name="callCode" type="xs:integer" minOccurs="0"/>
<xs:element name="callbackType" type="CallbackType" minOccurs="0"/>
<xs:element name="callbackEmail" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The following stylesheet produces the intended result:
Notice the hard-coding of element types and use of
documentto retrieve them.Output: