Question

I'm attempting to convert a Time Zone value from one system to a different value to be pushed to another.

All good I wish they had of used state names instead of city names but never mind, this is an integration and can not be changed in both systems to just match each other.

I'm using XSLT to translate 1 xml document to another to do this.

In source system the time zone string one of the following:

Australia/Adelaide
Australia/Brisbane
Australia/Canberra
Australia/Darwin
Australia/Hobart
Australia/Melbourne
Australia/Perth
Australia/Sydney

In the target system the time zones are set up as per the following:

Australia/Adelaide
Australia/Brisbane
Australia/Canberra,Melbourne,Sydney
Australia/Darwin
Australia/Hobart
Australia/Perth

I know I can just use a <xsl:choose> and use <xs:when> etc to determine each string, but wanted to learn how to compare what's coming in from source against the enumeration source type, if it exists use it, if it doesn't exist then use a default value. Is this possible.

My enumeration in the xslt is defined per the target system as that what's required:

<xs:simpleType name="timeZoneType">
    <xs:restriction base="xs:string">
        <xs:enumeration value="Australia/Canberra,Melbourne,Sydney" />
        <xs:enumeration value="Australia/Adelaide" />
        <xs:enumeration value="Australia/Brisbane" />
        <xs:enumeration value="Australia/Darwin" />
        <xs:enumeration value="Australia/Hobart" />
        <xs:enumeration value="Australia/Perth" />
    </xs:restriction>
</xs:simpleType>

Cheers in advance for any help

Was it helpful?

Solution

If you can use a schema-aware XSLT 2.0 processor you can do

<xsl:if test="$in castable as timeZoneType">

If you can't, then you'll have to hand-craft it. You could of course generate the XSLT code by processing your schema document through an XSLT transformation.

OTHER TIPS

wanted to learn how to compare what's coming in from source against the enumeration source type, if it exists use it, if it doesn't exist then use a default value.

In XSLT 1.0 (at least), I believe it would be best to use an external lookup table in XML format, for example:

<lookup>
    <entry>
        <input>Australia/Canberra</input>
        <input>Australia/Melbourne</input>
        <input>Australia/Sydney</input>
        <output>Australia/Canberra,Melbourne,Sydney</output>
    </entry>
</lookup>

If the source value matches one of the input values, you would use the matching entry's output value as the output; otherwise the source input value gets passed to the output as is.

Note that your schema does not provide the necessary information to effect this replacement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top