XSL Transformations

XSL Transformations

This is a really good resource for xsl transformations. One of the useful things to me is the section about using xsl:element and xsl:attribute when transforming from xml to xml.

http://www.ibiblio.org/xml/books/bible2/chapters/ch17.html#d1e6328

I had an interesting case where I needed to transform an “extensible” database model into a more usable xml structure.

This is the original output of a SQL Server stored proc using For Xml Auto:

<root>
<transaction transactionid=”1″>
<vendor vendordescription=”DU”>
<status statusdescription=”Created”>
<transactionattribute attributeid=”1″ attributekey=”TestAttribute1″
attributevalue=”TestValue1″ attributedatatype=”String”>
<transactionattribute attributeid=”2″ attributekey=”TestAttribute2″
attributevalue=”TestValue2″ attributedatatype=”String”>
</transactionattribute>
</transactionattribute>
</status>
</vendor>
</transaction>
</root>

I needed the output to be in a format somewhat like this:

<transactions>
<transaction>
<transactionid>1</transactionid>
<vendorname>DU</vendorname>
<status>Created</status>
<testattribute1>TestValue1</testattribute1>
<testattribute2>TestValue2</testattribute2>
</transaction>
</transactions>

So, to accomplish this I created this xsl transformation script:

<?xml version=”1.0″ encoding=”ISO-8859-1″ ?>
<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”&gt;
<xsl:output method=”xml” indent=”yes” omit-xml-declaration=”no” />
<xsl:template match=”/”>
<Transactions>
<Transaction>
<xsl:element name=”TransactionID”>
<xsl:value-of select=”//Transaction/@TransactionID” />
</xsl:element>
<xsl:element name=”VendorName”>
<xsl:value-of select=”//Vendor/@VendorDescription” />
</xsl:element>
<xsl:element name=”Status”>
<xsl:value-of select=”//Status/@StatusDescription” />
</xsl:element>
<xsl:for-each select=”//TransactionAttribute”>
<xsl:element name=”{@AttributeKey}”>
<xsl:value-of select=”@AttributeValue” />
</xsl:element>
</xsl:for-each>
</Transaction>
</Transactions>
</xsl:template>
</xsl:stylesheet>

Advertisement

BizTalk Server Orchestration – message has not been initialized in construct statement

BizTalk Server Orchestration – message has not been initialized in construct statement

This may sound very basic…but…

When using the MessageAssignment orchestration shape, if the message you are using has not been instantiated by a map or a port then you must manually instantiate the message:

Message_Type = new System.Xml.XmlDocument();

//Now that the message has been instantiated it can be used.

Message_Type.[PropertyName] = “Property Value”;

Mark Schmidt’s Abode : Creating Multiple Input Maps for BizTalk Server 2004

I may use this to compose multipart mime documents.

…Update:
I discovered an issue with this post. I was only able to get the BizTalk Mapper to launch when the schemas used in the example were in the same project as the orchestration. There may be another solution, but I don’t have time to look for one! I think the reason for the problem is the namespacing used in the schemas I downloaded in the example. -j

…Update 2:
This method only works if the target namespace of all the input maps is defined. If the namespaces are not defined then the map generated only carries across the source schema for the first message. -j