Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

XSLT Query - Enumeration mapping

Options
  • 11-11-2009 5:48pm
    #1
    Moderators, Science, Health & Environment Moderators Posts: 10,079 Mod ✭✭✭✭


    Hi guys, if there are any XML gurus, I have a question. (This is a simplified version of my real world scenario)

    I have an xml source document that has a single element that can accept the numbers 1,2, or 3. The target document has a single element that can takethe values one, two or three". (Both of these are constrained by enumeration restrictions).

    Is there any way in XSL that I can take the number from the source document, and map it to the position of the enumerator of the second document, in order to return the string representation. (Like you would do if it was in a programming language array).

    In my real program I am mapping potentially hundreds of codes to status strings, so a simple harcoded xsl:choice solution is not an option (The enumerators are guaranteed to be defined in the correct order so that will not be an issue).

    Also I cannot alter either of the real schemas (the real ones are EDIFACT and xCBL).

    So I end up with the following mappings:
    <Source><DigitNumber> 1 <DigitNumber></Source>  --> <Target><NumberStringText> One </NumberStringText></Target>
    <Source><DigitNumber> 2 <DigitNumber></Source>  --> <Target><NumberStringText> Two</NumberStringText></Target>
    <Source><DigitNumber> 3 <DigitNumber></Source>  --> <Target><NumberStringText> Three</NumberStringText></Target>
    

    Source Doc:
    <xs:schema >
      <xs:element name="Source">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="DigitNumber" type="anumber" />
          </xs:sequence>
        </xs:complexType>
      /xs:element>
    
    	<xs:simpleType name="anumber">
    		<xs:restriction base="xs:int">
    			<xs:enumeration value="1" />
    			<xs:enumeration value="2" />
    			<xs:enumeration value="3" />
    		</xs:restriction>
    	</xs:simpleType>
    </xs:schema>
    

    Target Doc:
    <xs:schema >
    
      <xs:element name="Target">
         <xs:complexType>
          <xs:sequence>
            <xs:element name="NumberString" type="numberstring" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    
    	<xs:simpleType name="numberstring">
    		<xs:restriction base="xs:string">
    			<xs:enumeration value="One" />
    			<xs:enumeration value="Two" />
                            <xs:enumeration value="Three" />
    		</xs:restriction>
    	</xs:simpleType>
    </xs:schema>
    


    Thanks,
    Marco


Advertisement