Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Help with speeding up xslt
- This topic has 2 replies, 1 voice, and was last updated 9 years, 10 months ago by
community-content.
-
AuthorPosts
-
-
June 30, 2008 at 4:42 PM #20035
Hi.
I have a map that is realy slow when lagre files comes as input.
I have found the function that is slowing it down. It’s an xslt template.
Ex from source schema
(…)
Header
HeaderText /
FooterText /
FreeHeaderText
Id
Text /
FreeFooterText
Id
Text /
/Header
(…)
Ex data from source:
<header>
<HeaderText>testData</HeaderText>
<FooterText>testData</FooterText>
<HeaderFreeText>
<Id>1</Id>
<Text>Test1</Text>
</HeaderFreeText>
<HeaderFreeText>
<Id>2</Id>
<Text>test2</Text>
</HeaderFreeText>
<HeaderFreeText>
<Id>3</Id>
<Text>Test3</Text>
</HeaderFreeText>
<FooterFreeText>
<Id>1</Id>
<Text>test1</Text>
</FooterFreeText>
<FooterFreeText>
<Id>2</Id>
<Text>test2</Text>
</FooterFreeText>
</header>
Ex destination schema
(…)
FreeText
Text
FTValueParameter
Name
Value /
/Text
/FreeText
(…)
Ex data from destination
<FreeText>
<Text>
<FTValueParameter name=”HEAD” value=”TestData”/>
<FTValueParameter name=”HEAD1″ value=”Test1″/>
<FTValueParameter name=”HEAD2″ value=”Faktura gjelder kommunale gebyrer og eiendomsskatt: 3. KVARTAL 2008″/>
<FTValueParameter name=”HEAD3″ value=” Test3″/>
<FTValueParameter name=”FOOT” value=”TestData”/>
<FTValueParameter name=”FOOT1″ value=” Test1″/>
<FTValueParameter name=”FOOT2″ value=” Test2″/>
</Text>
</FreeText>
I tried to make all go into an “Table looping” but I couldn’t get I to work, so I made this xslt template:
<xsl:param name=”HeadText” />
<xsl:param name=”FootText” />
<xsl:param name=”invoiceCount” />
<!– HeaderText –>
<xsl:if test=”$HeadText”>
<FTValueParameter><xsl:attribute name=”name”>HEAD</xsl:attribute><xsl:attribute name=”value”><xsl:value-of select=”$HeadText”/></xsl:attribute></FTValueParameter>
</xsl:if>
<!– HeaderFreeText –>
<xsl:for-each select=”/ABWInvoice/Invoice[position()=$invoiceCount]/Header/HeaderFreeText”>
<FTValueParameter><xsl:attribute name=”name”>HEAD<xsl:value-of select=”Id”/></xsl:attribute><xsl:attribute name=”value”><xsl:value-of select=”Text”/></xsl:attribute></FTValueParameter>
</xsl:for-each>
<!– FooterText –>
<xsl:if test=”$FootText”>
<FTValueParameter><xsl:attribute name=”name”>FOOT</xsl:attribute><xsl:attribute name=”value”><xsl:value-of select=”$FootText”/></xsl:attribute></FTValueParameter>
</xsl:if>
<!– FooterFreeText –>
<xsl:for-each select=”/ABWInvoice/Invoice[position()=$invoiceCount]/Header/FooterFreeText”>
<FTValueParameter><xsl:attribute name=”name”>FOOT<xsl:value-of select=”Id”/></xsl:attribute><xsl:attribute name=”value”><xsl:value-of select=”Text”/></xsl:attribute></FTValueParameter>
</xsl:for-each>
</xsl:template>
The two for-each are the slow, since they find the node out from the position, sent in from iteration.
Does anyone have a better suggestion so I could speed this up? When I remove the for-each statements the maps runs almost 70 percent faster on a 70 MB file, so it will be nice with some help J
-
July 1, 2008 at 1:52 AM #20038
The issue here is the having to rescan the document twice per call to this template, which is called for every invoice in the original file.
Using real Xslt you would pass the template an invoice node and the template would work within that node.
so your actual Xslt would look like this:
…
<xsl:for-each select=“Invoice“>
<xsl:call-template name=“MapText“>
<xsl:param name=“Invoice“ select=“.“/>
</xsl:call-template>
</xsl:for-each>
<xsl:template>
<xsl:template name=“MapText“>
<xsl:param name=“Invoice“ />
….
<xsl:template>The problem is the Biztalk Mapper only allows
you to pass a string to a Xslt Call template.
A trick I have used is to create a Xslt Call Template, but do not connect it to anything
Then use an Inline Xslt scripting functoid to call the Xslt template.You inline Xslt functoid would contain this Xslt:
<xsl:call-template name=”MapText”>
<xsl:param name=”Invoice” select=”.”/>
</xsl:call-template>And the output of this functoid connects to the FreeText/Text node on the destination schema.
Your Xslt Call Template would contain this xslt., or similar
<xsl:template name=“MapText“>
<xsl:param name=“Invoice“ />
<!– HeaderText –>
<xsl:if test=“$Invoice/Header/HeadText“>
<FTValueParameter>
<xsl:attribute name=“name“>HEAD</xsl:attribute>
<xsl:attribute name=“value“>
<xsl:value-of select=“$Invoice/Header/HeadText“/>
</xsl:attribute>
</FTValueParameter>
</xsl:if>
<!– HeaderFreeText –>
<xsl:for-each select=“$Invoice/Header/HeaderFreeText“>
<FTValueParameter>
<xsl:attribute name=“name“>HEAD<xsl:value-of select=“Id“/>
</xsl:attribute>
<xsl:attribute name=“value“>
<xsl:value-of select=“Text“/>
</xsl:attribute>
</FTValueParameter>
</xsl:for-each>
<!– FooterText –>
<xsl:if test=“$Invoice/Header/FootText“>
<FTValueParameter>
<xsl:attribute name=“name“>FOOT</xsl:attribute>
<xsl:attribute name=“value“>
<xsl:value-of select=“$Invoice/Header/FootText“/>
</xsl:attribute>
</FTValueParameter>
</xsl:if>
<!– FooterFreeText –>
<xsl:for-each select=“$Invoice/Header/FooterFreeText“>
<FTValueParameter>
<xsl:attribute name=“name“>FOOT<xsl:value-of select=“Id“/>
</xsl:attribute>
<xsl:attribute name=“value“>
<xsl:value-of select=“Text“/>
</xsl:attribute>
</FTValueParameter>
</xsl:for-each>
</xsl:template>There are many variables that come into play when attempting this patterm, using the Test Map and Validate Map to inpect the resulting Xslt from the mapper compilation is always a good idea. Some times you need to add the surrounding nodes like FreeText and Text to your template and adjust the location the Inline Xslt functoid maps to.
If this gets too hard I resort to using custom Xslt. Use the Validate Map to produce the Xslt, save this file and add to your project, configure the map’s custom Xslt property to point to this xslt file.
-
July 1, 2008 at 9:15 AM #20053
Thanks for a very good answer. I tried the last bit, configured the map’s custom Xslt property to point to the xslt file. It went about 20 percent faster, so it helps 🙂 I will try do do your first suggestion, do you think it will improve perfomance much? Any other special tips for speeding up? 🙂
-
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.