This is my new (edited) more complete scenario: I got a xml, that will transform with xsl. I got an example from the customer, that looks like: XML that is infile:
<?xml version="1.0" encoding="utf-8"?>
<xsi:myCompanyImport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tns:myCompanyHeader xmlns:tns="http://www.MyComp.se/myCompany">
<tns:sentFr>123456</tns:sentFr>
</tns:myCompanyHeader>
<tns:myCompanyUsers xmlns:tns="http://www.MyComp.se/myCompany">
<tns:myCompanyUser ssn="1234567890">
<tns:firstName>John</tns:firstName>
</tns:myCompanyUser>
</tns:myCompanyUsers>
</xsi:myCompanyImport>
XSL-file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:tns="http://www.MyComp.se/myCompany"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.MyComp.se/myCompany myCompanyUsers.xsd"
xmlns:local="urn:cs">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<xsl:element name="xsi:myCompanyImport" namespace="http://www.w3.org/2001/XMLSchema-instance">
<!--Start Header-->
<xsl:element name="tns:myCompanyHeader" >
<xsl:element name="tns:sentFr" >
<xsl:value-of select="_x0023_MyComp_header/@SentFrom" />
</xsl:element>
</xsl:element>
<!--End Header-->
<!--Start Users-->
<xsl:element name="tns:myCompanyUsers">
<!--Loop through persons-->
<xsl:for-each select="_x0023_MyComp_header/_x0023_MyComp_Employee">
<xsl:element name="tns:myCompanyUser" >
<xsl:attribute name="ssn">
<xsl:value-of select="@inSsn" />
</xsl:attribute>
<xsl:element name="tns:firstName" >
<xsl:value-of select="@inFname"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
<!--End Loop-->
</xsl:element>
<!--End Users-->
</xsl:element>
</xsl:template>
</xsl:stylesheet>
(Nevermind about the Csharp-code in the xsl, it's used for purposes not shown here.) So, the result is now:
<?xml version="1.0" encoding="utf-8"?>
<xsi:myCompanyImport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tns:myCompanyHeader xmlns:tns="http://www.MyComp.se/myCompany">
<tns:sentFr>123456</tns:sentFr>
</tns:myCompanyHeader>
<tns:myCompanyUsers xmlns:tns="http://www.MyComp.se/myCompany">
<tns:myCompanyUser ssn="1234567890">
<tns:firstName>John</tns:firstName>
</tns:myCompanyUser>
</tns:myCompanyUsers>
</xsi:myCompanyImport>
But the customer wants:
<?xml version="1.0" encoding="utf-8"?>
<xsi:myCompanyImport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tns:myCompanyHeader xmlns:tns="http://www.MyComp.se/myCompany">
<tns:sentFr>123456</tns:sentFr>
</tns:myCompanyHeader>
<tns:myCompanyUsers xmlns:tns="http://www.MyComp.se/myCompany"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.maxm.se/myCompany myCompanyUsers.xsd">
<tns:myCompanyUser ssn="1234567890">
<tns:firstName>John</tns:firstName>
</tns:myCompanyUser>
</tns:myCompanyUsers>
</xsi:myCompanyImport>
How can I write this in the xsl so that shows up in the xml? I've tried many different ways, but with no success. It's actually just those 2 lines I would add to tns:myCompanyUsers:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.maxm.se/myCompany myCompanyUsers.xsd">
I want in. But no success!