0
votes

I'm new to BizTalk and I'm having problems with adding a namespace to my output file.

I need to get the following output, with the namespace at the root level:

<?xml version="1.0" encoding="utf-8"?>
<TestExternalPO xmlns="http://Test.EDI.TestExternalPO.Schemas">
 <Routing/>
 <POHeader/>
</TestExternalPO>

My xsd is:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           xmlns:b="http://schemas.microsoft.com/BizTalk/2003" 
           elementFormDefault="qualified" version="1.0">
<xs:annotation>
<xs:appinfo>
     <b:schemaInfo BizTalkServerEditorTool_Version="1.5"     root_reference="TestExternalPO"
      displayroot_reference="TestExternalPO" standard="XML"
    targetNamespace="http://Test.EDI.TestExternalPO.Schemas"
   xmlns:b="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>

My xslt is:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:apply-templates select="TestExternalPO"/>
</xsl:template>

<xsl:template match="TestExternalPO">
<TestExternalPO xmlns="http://Test.EDI.TestExternalPO.Schemas">
  <Routing>....

Any help greatly appreciated,

Maggs

Update 25-Apr. Thanks for all the comments. The above setup works but doesn't give me what I want i.e namespace at root level.

I did test the namespace in the xslt but got an error on BizTalk.

<xsl:template match="TestExternalPO">
      <TestExternalPO xmlns="http://Test.EDI.TestExternalPO.Schemas">
        <Routing>
          <xsl:attribute name="SendPartner">

BizTalk Error - Finding the document specification by message type "http://Test.EDI.TestExternalPO.Schemas" failed. Verify the schema deployed properly.

Below is structure of input file:

<TestExternalPO>
  <POHeader>    
  </POHeader>
  <TradingPartnersList>
    <TradingPartners>   
    </TradingPartners>
  </TradingPartnersList>
  <Contract>   
  </Contract>
  <ItemsList>
    <Items>
    </Items>
  </ItemsList>
</TestExternalPO>

The problem is with my declaration of 'xmlns'. If I add 'targetNamespace', then output has the targetNamespace at the root element.

This works:

<xsl:template match="TestExternalPO">
      <TestExternalPO targetNamespace="http://Test.EDI.TestExternalPO.Schemas">
        <Routing>
          <xsl:attribute name="SendPartner">

Again thanks for the help. Maggs

1
Please post an example of the input and a complete stylesheet - see: minimal reproducible example. - michael.hor257k
Do you really need the Namespace? If you own the schema, my recommendation is to not use one. - Johns-305
It would help to give us at least the input file and why it causes you issues. Seeing from your XSLT, you are trying to map the MessageType #TestExternalPO (= without any namespace)? - Pieter Vandenheede
Added some extra detail - Maggs091

1 Answers

0
votes

Here's how your xslt should look. You want to exclude namespace so add the prefix to exclude-result-prefixes

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                exclude-result-prefixes="ns0"
                xmlns:ns0="http://Test.EDI.TestExternalPO.Schemas">

<xsl:template match="/">
<xsl:apply-templates select="TestExternalPO"/>
</xsl:template>

<xsl:template match="TestExternalPO">
<ns0:TestExternalPO> 
  <Routing>....