Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

XSLT Query - Enumeration mapping

  • 11-11-2009 04:48PM
    #1
    Moderators, Science, Health & Environment Moderators Posts: 10,093 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