Search This Blog

XSLT Mapping Simple Type to Complex Type ( MaxOccurs="unbounded" ) Oracle BPM 11g

XSLT Mapping Simple Type to Complex Type ( MaxOccurs="unbounded" )



XSL - XML Style Sheet 

Purpose of  XSL used to transform XML data from One form to another form. Let me show how to use
xslt to transform simple type to complex  type mapping.

Simple types:

Most of websites now a days have a provision to enter

PhoneNumber                            PhoneType

* Work Phone Number       -              01
* Mobile Phone Number     -              02
* Home Phone Number.      -              03


XSD Structure :


XSD Structure : (Simple Type) Flat Structure


<xsd:element name="SimpleEmelemnt">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="WorkPhoneNum" type="xsd:string"/>
        <xsd:element name="MobilePhoneNum" type="xsd:string"/>
        <xsd:element name="HomePhoneNum" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>



XSD Structure : ( Complex Type ) MaxOccurance - Unbound


<xsd:element name="ComplexElement">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="PhoneNum" type="PhoneNum" minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

    <xsd:complexType name="PhoneNum">
      <xsd:sequence>
        <xsd:element name="PhoneType" type="xsd:string"/>
        <xsd:element name="PhoneNumber" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>



XSLT Mapping Simple Type to Complex Type ( MaxOccurs="unbounded" )





XSL Mapping Using For-each


 <xsl:template match="/">
    <ns0:ComplexElement>

      <xsl:for-each select="/ns0:SimpleEmelemnt/ns0:WorkPhoneNum">
        <ns0:PhoneNum>
          <ns0:PhoneType>
            <xsl:text disable-output-escaping="no">01</xsl:text>
          </ns0:PhoneType>
          <ns0:PhoneNumber>
            <xsl:value-of select="."/>
          </ns0:PhoneNumber>
        </ns0:PhoneNum>
      </xsl:for-each>

      <xsl:for-each select="/ns0:SimpleEmelemnt/ns0:MobilePhoneNum">
        <ns0:PhoneNum>
          <ns0:PhoneType>
            <xsl:text disable-output-escaping="no">02</xsl:text>
          </ns0:PhoneType>
          <ns0:PhoneNumber>
            <xsl:value-of select="."/>
          </ns0:PhoneNumber>
        </ns0:PhoneNum>
      </xsl:for-each>

      <xsl:for-each select="/ns0:SimpleEmelemnt/ns0:HomePhoneNum">
        <ns0:PhoneNum>
          <ns0:PhoneType>
            <xsl:text disable-output-escaping="no">03</xsl:text>
          </ns0:PhoneType>
          <ns0:PhoneNumber>
            <xsl:value-of select="."/>
          </ns0:PhoneNumber>
        </ns0:PhoneNum>
      </xsl:for-each>
    </ns0:ComplexElement>
  </xsl:template>



Done .......................................................................
Thank you.

No comments:

Post a Comment