0
votes

My Source XSD for XSL transformation:

<?xml version= '1.0' encoding= 'UTF-8' ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.quo.com"
            targetNamespace="http://www.quo.com"
            elementFormDefault="qualified"
            xmlns:emc="http://www.quo.com"
<xsd:complexType name="HeaderType">
  <xsd:sequence>
   <xsd:element name="messageId" type="xsd:string"/>
   <xsd:element name="messageType" type="xsd:string"/>
  </xsd:sequence>
  <xsd:attribute name="version" type="xsd:int"/>
</xsd:complexType>   
<xsd:complexType name="ResponseType">
  <xsd:sequence>
   <xsd:element name="errorCode" type="xsd:string"/>
   <xsd:element name="errorString" type="xsd:string"/>
  </xsd:sequence>
</xsd:complexType> 
<xsd:element name="AckMessage">
  <xsd:complexType>
   <xsd:sequence>
    <xsd:element name="header" type="HeaderType"/> 
    <xsd:element name="payload" type="xsd:string"/> 
   </xsd:sequence>
  </xsd:complexType>
</xsd:element>
<xsd:element name="response" type="ResponseType"/>  
</xsd:schema>

My Sample XML for Source XSD is:

<AckMessage>
<header  version="1">
 <messageId>messageId1</messageId>
 <messageType>sourceSystemId2</messageType>
</header>
 <payload>
  <bookstore>
   <book>
    <title  lang="en">Harry Potter</title>
    <author>J K Rowling</author>
    <year>2005</year>
    <price>29.99</price>
   </book>
   <book>
    <title  lang="en">Harry Potter 1</title>
    <author>J K Rowling</author>
    <year>2006</year>
    <price>29.99</price>
   </book>
  </bookstore>
 </payload>
</AckMessage>

The payload element in source XSD is string type in which I am getting the whole XML fragment for root element bookstore

My Target XSD for XSL transformation:

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.quo.com/ns/bookstore"
            targetNamespace="http://www.quo.com/ns/bookstore"
            elementFormDefault="qualified">
  <xsd:element name="bookstore">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="book" maxOccurs="unbounded">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="title">
                <xsd:complexType>
                  <xsd:simpleContent>
                    <xsd:extension base="xsd:string">
                      <xsd:attribute name="lang" type="xsd:string"/>
                    </xsd:extension>
                  </xsd:simpleContent>
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="author" type="xsd:string"/>
              <xsd:element name="year" type="xsd:integer"/>
              <xsd:element name="price" type="xsd:float"/>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

I want to transform the Payload element from source to bookstore element of target schema.

When I trying to do by simple transformation, I am getting error that cannot transform simple element to XML element.

I tried xsl:

  <xsl:variable name="variable1">
    <xsl:value-of select="/msg_in_out:esbAckMessage/msg_in_out:payload"
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
  </xsl:variable>
  <xsl:template match="/">
    <imp1:bookstore>
          <xsl:value-of select="$variable1"/>
    </imp1:bookstore>
  </xsl:template>
</xsl:stylesheet>

But I am getting output as

<?xml version = '1.0' encoding = 'UTF-8'?>
<imp1:bookstore xmlns:imp1="http://www.quo.com/ns/bookstore">


        Harry Potter
        J K Rowling
        2005
        29.99


        Harry Potter 1
        J K Rowling
        2006
        29.99


   </imp1:bookstore>

How can I get everything inside Payload element with Xml tags?

The answer is use copy-of

  <xsl:variable name="variable1">
    <xsl:value-of select="/msg_in_out:esbAckMessage/msg_in_out:payload"
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
  </xsl:variable>
  <xsl:template match="/">
    <imp1:bookstore>
          <xsl:copy-of select="$variable1"/>
    </imp1:bookstore>
  </xsl:template>
</xsl:stylesheet>
1
Where is your xsl file? Please show all relevant code.OldProgrammer
If the schemas matter, then please show valid instances, it doesn't make sense to show schemas with target namespaces but instance documents not using any namespaces. And of course if you tell us the payload element is of type string then the alleged input sample you have shown does not make sense at all, it either needs escaped markup or a CDATA section.Martin Honnen
Hi Martin,My Sample xml is valid and I am using Oracle SOA for webservice, so My websrvice accept the sample XML for source XSD and then I am using Xsl in BPEL process to pass the "payload" value to target element Bookstore.user5568021
Hi Martin, If you see the xml fragment inside Payload element matches the target Bookstore element. I am trying to pass the XML fragment inside payload element to Target's Bookstore element. If you validate my sample XML with source XSD it is showing valid and I am passing XML using SOAP UI to my SOA Bpel webservice.user5568021
@MartinHonnen I used <xsl:variable name="variable1"> <xsl:value-of select="/msg_in_out:AckMessage/msg_in_out:payload" xmlns:xsl="w3.org/1999/XSL/Transform"> </xsl:variable> <xsl:template match="/"> <imp1:bookstore> <xsl:value-of select="$variable1"/> </imp1:bookstore> </xsl:template> </xsl:stylesheet>user5568021

1 Answers

0
votes

The answer is use copy-of

  <xsl:variable name="variable1">
    <xsl:value-of select="/msg_in_out:esbAckMessage/msg_in_out:payload"
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
  </xsl:variable>
  <xsl:template match="/">
    <imp1:bookstore>
          <xsl:copy-of select="$variable1"/>
    </imp1:bookstore>
  </xsl:template>
</xsl:stylesheet>