Hi all, I'm new to XML/ XSLT. My task is to generate xml in the below structure and send it restful server through ASP.NET application. Could you help me to produce the below structure using XSLT in VS2010 please? Thanks in advance.
Required output XML:
="1.0"="UTF8"
<MyTalkTalkMessage xmlns="http://www.Testwebsite.com/xx/dunlop" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"
xmlns:gt="http://www.Testwebsite.com/schemas/freetalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.Testwebsite.com/xx/dunlop http://xmlws.Testwebsite.com/v10/schema/Etalk_mychapter.xsd">
<dunlopVersion>1.0</dunlopVersion>
<dunHeader>
<dunMessageDetails>
<dunClass>ClassName</dunClass>
</dunMessageDetails>
</dunHeader>
<Body>
<MyTestSubmit xmlns="http://xmlws.Testwebsite.com/MyHeader" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlws.Testwebsite.com/Header http://xmlws.Testwebsite.com/v123/schema/wsforms/MyTestFormSubmit.xsd"
xmlns:bs="http://xmlws.Testwebsite.com">
<myDateSig>19990102</myDateSig>
<Form>
<myPets xmlns="http://xmlws.Testwebsite.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlws.Testwebsite.com http://xmlws.Testwebsite.com/v123/schema/wsforms/myPetreturn342.xsd">
<Pets>
<petCompCode>1234</petCompCode>
</Pets>
<PetVETAddress>
<VetPetAddress>Address</VetPetAddress>
</PetVETAddress>
</myPets>
</Form>
</MyTestSubmit>
</Body>
</MyTalkTalkMessage>
In my xslt, I have included all the namespaces but when transformed the xslt, the xml has been generated without
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
in
<mytestsubmit> & <mypets>
sections of my output xml
My xslt:
="1.0"
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="no"/>
<xsl:template match="/">
<xsl:apply-templates select="/Test" />
</xsl:template>
<xsl:template match="Test">
<MyTalkTalkMessage xmlns="http://www.Testwebsite.com/xx/dunlop" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"
xmlns:gt="http://www.Testwebsite.com/schemas/freetalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.Testwebsite.com/xx/dunlop http://xmlws.Testwebsite.com/v10/schema/Etalk_mychapter.xsd">
<dunlopVersion>1.0</dunlopVersion>
<dunHeader>
<dunMessageDetails>
<dunClass><xsl:value-of select="Test/dunClass"/></dunClass>
</dunMessageDetails>
</dunHeader>
<Body>
<MyTestSubmit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bs="http://xmlws.Testwebsite.com"
xsi:schemaLocation="http://xmlws.Testwebsite.com/Header http://xmlws.Testwebsite.com/v123/schema/wsforms/MyTestFormSubmit.xsd" xmlns="http://xmlws.Testwebsite.com/MyHeader">
<myDateSig>
<xsl:variable name="dts" select="Test/SigDate"/>
<xsl:value-of select="concat(substring($dts, 1, 4), '-',
substring($dts, 6, 2), '-', substring($dts, 9, 2))"/>
</myDateSig>
<Form>
<myPets xmlns="http://xmlws.Testwebsite.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlws.Testwebsite.com http://xmlws.Testwebsite.com/v123/schema/wsforms/myPetreturn342.xsd">
<Pets>
<petCompCode><xsl:value-of select="Test/CompCode"/></petCompCode>
</Pets>
<PetVETAddress>
<VetPetAddress><xsl:value-of select="Test/Add1"/></VetPetAddress>
</PetVETAddress>
</myPets>
</Form>
</MyTestSubmit>
</Body>
</MyTalkTalkMessage>
</xsl:template>
</xsl:stylesheet>
C# code:
{
XslCompiledTransform myXslTrans = new XslCompiledTransform(); myXslTrans.Load(HttpContext.Current.Server.MapPath("~/Test/InputXSLT.xslt")); myXslTrans.Transform(HttpContext.Current.Server.MapPath("~/Test/OutputXML.xml"), myXMLPath + "\\" + xmlFileName);
}
My output XML
="1.0"="UTF-8"
<MyTalkTalkMessage xmlns="http://www.Testwebsite.com/xx/dunlop" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"
xmlns:gt="http://www.Testwebsite.com/schemas/freetalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.Testwebsite.com/xx/dunlop http://xmlws.Testwebsite.com/v10/schema/Etalk_mychapter.xsd">
<dunlopVersion>1.0</dunlopVersion>
<dunHeader>
<dunMessageDetails>
<dunClass>ClassName</dunClass>
</dunMessageDetails>
</dunHeader>
<Body>
<MyTestSubmit xmlns="http://xmlws.Testwebsite.com/MyHeader"
xsi:schemaLocation="http://xmlws.Testwebsite.com/Header http://xmlws.Testwebsite.com/v123/schema/wsforms/MyTestFormSubmit.xsd"
xmlns:bs="http://xmlws.Testwebsite.com">
<myDateSig>19990102</myDateSig>
<Form>
<myPets xmlns="http://xmlws.Testwebsite.com"
xsi:schemaLocation="http://xmlws.Testwebsite.com http://xmlws.Testwebsite.com/v123/schema/wsforms/myPetreturn342.xsd">
<Pets>
<petCompCode>1234</petCompCode>
</Pets>
<PetVETAddress>
<VetPetAddress>Address</VetPetAddress>
</PetVETAddress>
</myPets>
</Form>
</MyTestSubmit>
</Body>
</MyTalkTalkMessage>
Could you advise me how to generate a required output xml please? TIA.