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>
</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>
</xsl:text>
</xsl:template>
<xsl:template match="*">
<xsl:if test="string-length(normalize-space(text()))=0">
<xsl:text>
</xsl:text>
<xsl:value-of select="local-name()"/>
<xsl:text>
</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>
</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
I finally resolved my own question, as follows.
Developed the following XSL stylesheet to transform the input message to a normal XML document:
A sample XML document created by the stylesheet looks like this in a text editor:
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:
In Visual Studio, the schema editor tree shows how simple the schema really is:
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: