XSLT- Header and LineItems Sequence Order in 1 field together
hi below xslt, want sendernumber appended sequenceordernumber , sequence number should same in complete header , lineitems.
<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" xmlns:s0="http://msdntestbiztalk.test2.inputschin" xmlns:ns0="http://msdntestbiztalk.test2.flatfileschemaout" exclude-result-prefixes="msxsl var s0" version="1.0"> <xsl:output omit-xml-declaration="yes" method="xml" version="1.0"/> <xsl:key name="sendernum" match="//details" use="sendernumber"/> <xsl:key name="key1" match="//details" use="concat(sendernumber,'|',sequencenumber)"/> <xsl:template match="/"> <xsl:apply-templates select="/s0:root"/> </xsl:template> <xsl:template match="/s0:root"> <ns0:root> <record> <xsl:for-each select="//details[count(. | key('sendernum', sendernumber)[1]) = 1]"> <xsl:sort select="sendernumber"/> <xsl:variable name="sendnum" select="sendernumber"/> <headerrecord> <invnumber> <xsl:value-of select="../header/invnumber/text()"/> </invnumber> <invdate> <xsl:value-of select="../header/invdate/text()"/> </invdate> <sendernumber> <xsl:choose> <xsl:when test="sum(lineitemsubtotal) < 0"> <xsl:value-of select="concat('a',$sendnum)"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$sendnum"/> </xsl:otherwise> </xsl:choose> </sendernumber> </headerrecord> <xsl:for-each select="//details[sendernumber = $sendnum]"> <xsl:variable name="seqnumber" select="sequencenumber"/> <xsl:variable name="seqtotal" select="sum(../details[sendernumber = $sendnum]/lineitemsubtotal/text())"/> <detailrecord> <sendernumber> <xsl:choose> <xsl:when test="$seqtotal < 0"> <xsl:value-of select="concat('a',$sendnum)"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$sendnum"/> </xsl:otherwise> </xsl:choose> </sendernumber> <sequencenumber> <xsl:value-of select="sequencenumber/text()"/> </sequencenumber> <lineitemsubtotal> <xsl:value-of select="lineitemsubtotal/text()"/> </lineitemsubtotal> </detailrecord> </xsl:for-each> </xsl:for-each> </record> </ns0:root> </xsl:template> </xsl:stylesheet>
this should do..
<?xml version="1.0"?> <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" xmlns:s0="http://msdntestbiztalk.test2.inputschin" xmlns:ns0="http://msdntestbiztalk.test2.flatfileschemaout" exclude-result-prefixes="msxsl var s0" version="1.0"> <xsl:output omit-xml-declaration="yes" method="xml" version="1.0"/> <xsl:key name="sendernum" match="//details" use="sendernumber"/> <xsl:key name="key1" match="//details" use="concat(sendernumber,'|',sequencenumber)"/> <xsl:template match="/"> <xsl:apply-templates select="/s0:root"/> </xsl:template> <xsl:template match="/s0:root"> <ns0:root> <record> <xsl:for-each select="//details[count(. | key('sendernum', sendernumber)[1]) = 1]"> <xsl:sort select="sendernumber"/> <xsl:variable name="sendnum" select="sendernumber"/> <xsl:variable name="headerposition" select="position()"/> <headerrecord> <invnumber> <xsl:value-of select="../header/invnumber/text()"/> </invnumber> <invdate> <xsl:value-of select="../header/invdate/text()"/> </invdate> <sendernumber> <xsl:choose> <xsl:when test="sum(lineitemsubtotal) < 0"> <xsl:value-of select="concat($sendnum,'-',format-number($headerposition, '000'), 'a')"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat($sendnum, '-',format-number($headerposition, '000'))"/> </xsl:otherwise> </xsl:choose> </sendernumber> </headerrecord> <xsl:for-each select="//details[sendernumber = $sendnum]"> <xsl:variable name="seqnumber" select="sequencenumber"/> <xsl:variable name="seqtotal" select="sum(../details[sendernumber = $sendnum]/lineitemsubtotal/text())"/> <detailrecord> <sendernumber> <xsl:choose> <xsl:when test="$seqtotal < 0"> <xsl:value-of select="concat($sendnum,'-', format-number($headerposition, '000'), 'a')"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat($sendnum,'-', format-number($headerposition, '000'))"/> </xsl:otherwise> </xsl:choose> </sendernumber> <sequencenumber> <xsl:value-of select="sequencenumber/text()"/> </sequencenumber> <lineitemsubtotal> <xsl:value-of select="lineitemsubtotal/text()"/> </lineitemsubtotal> </detailrecord> </xsl:for-each> </xsl:for-each> </record> </ns0:root> </xsl:template> </xsl:stylesheet>
pi_xel_xar
blog: my blog
biztalkapplicationdeploymenttool: biztalk application deployment tool/
BizTalk Server > BizTalk Server General
Comments
Post a Comment