2
votes

I have a very complex input message whose node names and values I need to regurgitate (without any namespace info) to the output as though viewing the document in a browser using an XSL stylesheet. I do not need to map any of the individual source XML elements to corresponding target elements. The output will be passed to a flat-file assembler and sent as a simple text message to the consumer.

For simplicity I removed most of the namespaces and changed prefixes in this stylesheet which produces exactly the output I desire:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:abcd="http://abcd.whatever.net/abcd/1.0.1" xmlns:info="http://info.sumthin.net/1.0.0" xmlns:wxyz="http://wxyz.widgetwonks.net/wxyz/3.0.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<xsl:output method="text" />

<xsl:template match="abcd:Message">
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="info:SpecialText">
    <xsl:text> </xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>&#010;</xsl:text>
</xsl:template>

<xsl:template match="wxyz:PersonSSN">
    <xsl:text> SSN: </xsl:text>
    <xsl:value-of select="substring(., 0, 4)"/>
    <xsl:text>-</xsl:text>
    <xsl:value-of select="substring(., 4, 2)"/>
    <xsl:text>-</xsl:text>
    <xsl:value-of select="substring(., 6, 4)"/>
    <xsl:text>&#010;</xsl:text>
</xsl:template>

<xsl:template match="*">
    <xsl:if test="string-length(normalize-space(text()))=0">
        <xsl:text>&#010;</xsl:text>
        <xsl:value-of select="local-name()"/>
    <xsl:text>&#010;</xsl:text>
    </xsl:if>

    <xsl:if test="not(string-length(normalize-space(text()))=0)">
        <xsl:text> </xsl:text>
        <xsl:value-of select="local-name()"/>: <xsl:value-of select="normalize-space(text())"/>
    </xsl:if>
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="text()|@*">
    <xsl:if test="string-length(normalize-space(.)) != 0">
        <xsl:text>&#010;</xsl:text>
    </xsl:if>
</xsl:template>

</xsl:stylesheet>

In BizTalk I have referenced this stylesheet on my map grid's "Custom XSL Path" property, and when I test the map I get the right output.

But how can I map this output to a target schema? The output of the stylesheet is just a very long stream of text with many x0D x0A (cr / lf) sprinkled in. I have not been able to devise a schema that BizTalk will permit to be a receptacle for the stylesheet output.

-Mark

2
It sounds like your output is basically a flat file. Have you tried using the flat file wizard to create a schema from an example output file?Jay
Jay: Thanks for asking. Yes, it's a flat file. But the flat-file wizard is no use because there are practically infinite permutations of the source data, which is a catch-all document type called "Message" that represents thousands of XML elements from dozens of business objects (and namespaces) on the source system. My goal is to direct the XSL stylesheet output into a single xs:string field, akin to what the browser does when it renders the source data as characters and carriage returns.CobolCommando

2 Answers

2
votes

I finally resolved my own question, as follows.

Developed the following XSL stylesheet to transform the input message to a normal XML document:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0 ScriptNS0" version="1.0" xmlns:s0="http://abcd.whatever.net/abcd/1.0.1" xmlns:ScriptNS0="http://schemas.microsoft.com/BizTalk/2003/ScriptNS0" xmlns:info="http://info.sumthin.net/1.0.0" xmlns:wxyz="http://wxyz.widgetwonks.net/wxyz/3.0.3">

<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />

<xsl:template match="/">
    <Message>
        <xsl:apply-templates />
    </Message>
</xsl:template>
<!-- <xsl:template match="/s0:Message" /> -->
<xsl:template match="info:CaveatText">
    <xsl:element name="TextField">
        <xsl:text>  </xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>&#010;</xsl:text>
    </xsl:element>
</xsl:template>

<xsl:template match="wxyz:PersonSSNID/wxyz:ID">
    <xsl:element name="TextField">
        <xsl:text>    SSN: </xsl:text>
        <xsl:value-of select="substring(., 0, 4)"/>
        <xsl:text>-</xsl:text>
        <xsl:value-of select="substring(., 4, 2)"/>
        <xsl:text>-</xsl:text>
        <xsl:value-of select="substring(., 6, 4)"/>
        <xsl:text>&#010;</xsl:text>
    </xsl:element>
</xsl:template>

<xsl:template match="*">
    <xsl:if test="string-length(normalize-space(text()))=0">
        <xsl:element name="TextField">
            <xsl:text>&#010;</xsl:text>
            <xsl:value-of select="local-name()"/>
            <xsl:text>&#010;</xsl:text>
        </xsl:element>
    </xsl:if>

    <xsl:if test="not(string-length(normalize-space(text()))=0)">
        <xsl:element name="TextField">
            <xsl:text>    </xsl:text>
            <xsl:value-of select="local-name()"/>: <xsl:value-of select="normalize-space(text())"/>
        </xsl:element>
    </xsl:if>
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="text()|@*">
    <xsl:if test="string-length(normalize-space(.)) != 0">
        <xsl:element name="TextField">
            <xsl:text>&#010;</xsl:text>
        </xsl:element>
    </xsl:if>
</xsl:template>

A sample XML document created by the stylesheet looks like this in a text editor:

<Message xmlns:{namespaces galore...}><TextField>
Message
</TextField><TextField>
HeaderArea
</TextField><TextField>    KeyText: PQ</TextField><TextField>
</TextField><TextField>    HeaderText: XYXY1010Z</TextField><TextField>
</TextField><TextField>
ResponseDataSection
</TextField><TextField>  **TEST**THIS RESPONSE IS FROM ABCD TEST SYSTEM.
</TextField><TextField>
PersonName
</TextField><TextField>    PersonGivenName: JACK</TextField><TextField>
</TextField><TextField>    PersonMiddleName: DANIEL</TextField><TextField>
</TextField><TextField>    PersonSurName: WEBBER</TextField><TextField>
</TextField><TextField>    PersonBirthDateText: 1975-01-31</TextField><TextField>
</TextField><TextField>
PersonAssignedIDDetails
</TextField><TextField>
PersonSSNID
</TextField><TextField>    SSN: 123-98-7654
</TextField><TextField>
PersonOtherID
</TextField><TextField>    ID: XT-01020304050</TextField><TextField>
</TextField><TextField>
PersonPhysicalDetails
</TextField><TextField>    PersonSexCode: M</TextField><TextField>
</TextField><TextField>    PersonRaceCode: W</TextField><TextField>
</TextField><TextField>
PersonAbcdID
</TextField><TextField>    ID: Z123456789</TextField><TextField>
</TextField><TextField>    ExpandedBirthDateSearch: 1</TextField><TextField>
</TextField><TextField>    ExpandedNameSearchIndicator: false</TextField><TextField>
</TextField><TextField>
VehicleID
</TextField><TextField>    ID: ASDFASDFASDFASDFA</TextField><TextField>
</TextField><TextField>    VehicleMakeText: DODG</TextField><TextField>
</TextField><TextField>
VehicleRegistrationPlateID
</TextField><TextField>    ID: ABC123</TextField><TextField>
</TextField><TextField>    IDJurisdictionText: AZ</TextField><TextField>
</TextField><TextField>
PrimaryResponse
</TextField><TextField>
PersonAlias
</TextField><TextField>
PersonAlternateName
</TextField><TextField>    PersonGivenName: JACK</TextField><TextField>
</TextField><TextField>    PersonMiddleName: ALLEN</TextField><TextField>
</TextField><TextField>    PersonSurName: DANIEL</TextField><TextField>
</TextField><TextField>
PersonAlternateName
</TextField><TextField>    PersonGivenName: JACKIE</TextField><TextField>
</TextField><TextField>    PersonSurName: DANIEL</TextField><TextField>
</TextField><TextField>
PersonAlternateName
</TextField><TextField>    PersonGivenName: JD</TextField><TextField>
</TextField><TextField>    PersonSurName: DANIEL</TextField><TextField>
</TextField><TextField>    PersonBirthDateText: 1967-01-01</TextField><TextField>
</TextField><TextField>    PersonBirthDateText: 1968-01-01</TextField><TextField>
</TextField><TextField>
PersonAssignedIDDetails
</TextField><TextField>
PersonSSNID
</TextField><TextField>    SSN: 234-00-0001
</TextField><TextField>
PersonSSNID
</TextField><TextField>    SSN: 345-00-0002
</TextField><TextField>
PersonSSNID
</TextField><TextField>    SSN: 456-00-0003
</TextField><TextField>
PersonSSNID
</TextField><TextField>    SSN: 567-00-0004
</TextField><TextField>
PersonOtherID
</TextField><TextField>    ID: XZ1234DE</TextField><TextField>
</TextField><TextField>
PersonOtherID
</TextField><TextField>    ID: YZE6241</TextField><TextField>
</TextField><TextField>
</Message>

In the above, the (...break to next line...) sequences are CR/LF generated by the stylesheet's pieces.

The schema for the message above is simple:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:xsi={application-specific namespace} xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
      <b:schemaInfo root_reference="Message" default_pad_char=" " pad_char_type="char" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="false" generate_empty_nodes="true" allow_early_termination="false" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" standard="Flat File" />
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="Message">
    <xs:annotation>
      <xs:appinfo>
        <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" />
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:annotation>
          <xs:appinfo>
            <b:groupInfo sequence_number="0" />
          </xs:appinfo>
        </xs:annotation>
        <xs:element maxOccurs="unbounded" name="TextField" type="xs:string">
          <xs:annotation>
            <xs:appinfo>
              <b:fieldInfo sequence_number="1" justification="left" />
            </xs:appinfo>
          </xs:annotation>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

In Visual Studio, the schema editor tree shows how simple the schema really is:

<Schema>                (Schema Editor Extensions is set to Flat File Extension)
    Message         (a record with no default properties)
        TextString      (a child element defined as unbounded)

BizTalk mapping: 1. There are no functoids on the map because it will use the custom XSLT file to produce a message using the target schema described above. 2. Using Validate Map, generated the Custom Extension XML file. 3. Added the Custom Extension XML and my stylesheet files to the project. 4. On the map design surface, set Custom Extension XML and Custom XSL Path properties by navigating to the files just mentioned.

Created a BizTalk pipeline that includes a Flat file assembler using the target schema.

Deployed the solution.

Configured the send port to use the new send-pipeline.

The final output is a flat file that looks like this:

Message

HeaderArea
    TransactionKeyText: PQ
    TransactionHeaderText: XYXY1010Z

ResponseDataSection
  **TEST**THIS RESPONSE IS FROM ABCD TEST SYSTEM.

PersonName
    PersonGivenName: JACK
    PersonMiddleName: DANIEL
    PersonSurName: WEBBER
    PersonBirthDateText: 1975-01-31

PersonAssignedIDDetails

PersonSSNID
    SSN: 123-98-7654

PersonOtherID
    ID: XT-01020304050

PersonPhysicalDetails
    PersonSexCode: M
    PersonRaceCode: W

PersonAbcdID
    ID: Z123456789
    ExpandedBirthDateSearch: 1
    ExpandedNameSearchIndicator: false

VehicleID
    ID: ASDFASDFASDFASDFA
    VehicleMakeText: DODG

VehicleRegistrationPlateID
    ID: ABC123
    IDJurisdictionText: AZ

PrimaryResponse

PersonAlias

PersonAlternateName
    PersonGivenName: JACK
    PersonMiddleName: ALLEN
    PersonSurName: DANIEL

PersonAlternateName
    PersonGivenName: JACKIE
    PersonSurName: DANIEL

PersonAlternateName
    PersonGivenName: JD
    PersonSurName: DANIEL
    PersonBirthDateText: 1967-01-01
    PersonBirthDateText: 1968-01-01

PersonAssignedIDDetails

PersonSSNID
    SSN: 234-00-0001

PersonSSNID
    SSN: 345-00-0002

PersonSSNID
    SSN: 456-00-0003

PersonSSNID
    SSN: 567-00-0004

PersonOtherID
    ID: XZ1234DE

PersonOtherID
    ID: YZE6241
0
votes

Define an output schema with a single string element. Then modify your xsl transformation to wrap your output in a CDATA section. Your output would be similar to this:

<?xml version="1.0" encoding="utf-8"?>
<MyOutputSchema>
<MyOutputString>
<![CDATA[<sender>Your output goes here</sender>]]>
</output-junk-drawer>
</MyOutputString>

The CDATA will allow invalid characters to be placed in the xml message. Then you can process the output with BizTalk.