BizTalk force empty elements to be created without

2019-07-24 06:12发布

问题:

Is there anyway in a BizTalk map to force destination elements to be created when the source elements don't exist without using an xslt call template?

I'm mapping parent/child xml to a wcf-sql adapter generated schema that has table-valued parameters for stored proc parameters.

So my source xml is:

<Category>
  <CategoryId>1</CategoryId>
  <CategoryName>Test</CategoryName>
</Category>

and/or a Category with Media

<Category>
  <CategoryId>1</CategoryId>
  <CategoryName>Test</CategoryName>
  <Media>
    <Medium>
      <MediumId>1</MediumId>
      <MediumName>test.jpg</MediumName>
    </Medium>
  </Media>
</Category>

The schema for the TypedProcedure is something like:

<ImportCategoryRequest>
  <Category>
    <CategoryId>1</CategoryId>
    <CategoryName>Test</CategoryName>
  </Category>
  <Media>
    <Medium>
      <MediumId>1</MediumId>
      <MediumName>test.jpg</MediumName>
    </Medium>
  </Media>
</ImportCategoryRequest>

So it doesn't like it when is all that shows up in the destination XML. Instead of passing null for a table-valued parameter it wants at least 1 row and to pass null values for the columns in the tvp. I can create the dummy xml with a xslt call-template but I'd like to avoid that.

回答1:

The BizTalk mapper seems to use <xsl:for-each> and as a result won't generate an output element if there is no input.

But using xslt is really easy - see here how to scrape the xslt out of your existing map (and just remove the escaping around double quotes and slashes), and to change the map to custom XSLT.

The bit you need to change is around the Media is something like:

        <xsl:choose>
            <xsl:when test="count(ns0:Media)!=0">
                <!-- Copy the mapper generated XSLT in the for each here-->
                <xsl:foreach >
                    </xsl:for-each>
                </xsl:when>
            <xsl:otherwise>
                <Media>
                    <Medium>
                        <MediumId>1</MediumId>
                        <MediumName>test.jpg</MediumName>
                    </Medium>
                </Media>
            </xsl:otherwise>
        </xsl:choose>


标签: BizTalk