xslt - Split XML to Multiple Htmls using XSL -
i have huge xml file , there "entryheaderheader" tag repeats more 9000 rows. wanted split 9 html documents (split 1000 rows)
i tried use xsl:result-document , mod operations failed. thank helps
all lines of xsl file
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:gl-bus="http://www.xbrl.org/int/gl/bus/2006-10-25" xmlns:gl-cor="http://www.xbrl.org/int/gl/cor/2006-10-25" xmlns:gl-gen="http://www.xbrl.org/int/gl/gen/2006-10-25" xmlns:iso4217="http://www.xbrl.org/2003/iso4217" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:xl="http://www.xbrl.org/2003/xlink" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:ext="http://exslt.org/common" xmlns:edefter="http://www.edefter.gov.tr"> <xsl:output version="4.0" omit-xml-declaration="yes" method="html" indent="no" encoding="utf-8" doctype-public="-//w3c//dtd html 4.01 transitional//en" doctype-system="http://www.w3.org/tr/html4/loose.dtd"/> <xsl:strip-space elements="*"/> <xsl:decimal-format name="tryformat" grouping-separator="." decimal-separator=","/> <xsl:variable name="vkn" select="/edefter:defter/xbrli:xbrl[1]/xbrli:context[1]/xbrli:entity[1]" /> <xsl:variable name="unvan" select="/edefter:defter/xbrli:xbrl[1]/gl-cor:accountingentries[1]/gl-cor:entityinformation/gl-bus:organizationidentifiers[gl-bus:organizationdescription = 'kurum unvanı' ]/gl-bus:organizationidentifier" /> <xsl:variable name="sube_adi" select="/edefter:defter/xbrli:xbrl[1]/gl-cor:accountingentries[1]/gl-cor:entityinformation/gl-bus:organizationidentifiers[gl-bus:organizationdescription = 'Şube adı' ]/gl-bus:organizationidentifier" /> <!-- donusturme islemi baslnagic yeri. edefter:defter --> <xsl:template match="/edefter:defter"> <html> <head> <style type="text/css"> body.bodyclass{ font-family:arial narrow; font-size:10pt; } table.pageheader1{ border:0; cellpadding:2; cellspacing:5; width:100%; font-weight:bold; } table.pageheader2{ border:0; width:100%; border-spacing: 6px; } table.pageheader2 tbody tr{ border-bottom-style:none; } table.pageheader2 tbody tr:nth-child(1) td{ border-bottom-color:black; border-bottom-style:dashed; border-bottom-width:thin; overflow:inherit; padding-bottom:2px; text-align:center; font-weight:bold; } table.pageheader2 tbody tr:nth-child(2) td{ border-top-color:black; border-top-style:dashed; border-top-width:thin; overflow:inherit; } table.entryheaderheader { width:100%; font-weight:bold; margin-bottom:20px; } table.entryheaderheader tr td:nth-child(1){ width:40%; padding-left:5px; } table.entryheaderheader tr td:nth-child(2){ width:45%; padding-left:5px; } table.entryheaderheader tr td:nth-child(3){ width:300px; } table.entryheaderheader tr td div:nth-child(2){ border-bottom-style:dashed; border-bottom-width:2px; border-color:black; font-size:1px; margin-top:-8px; margin-left:80px; margin-right:10px; } table.entrydetail{ border:0; overflow:hidden; width:100%; margin-top:5px; cellpadding:0; cellspacing:2; } table.entrydetail tr{ height:0.2in; } div.entryheaderfooter{ margin-bottom:15px; text-align:center; } </style> </head> <body class="bodyclass"> <xsl:apply-templates select="xbrli:xbrl" /> </body> </html> </xsl:template> <!-- xbrli:xbrl --> <xsl:template match="xbrli:xbrl"> <xsl:apply-templates select="gl-cor:accountingentries"/> </xsl:template> <!-- gl-cor:accountingentries --> <xsl:template match="gl-cor:accountingentries"> <xsl:apply-templates select="gl-cor:entityinformation"/> <xsl:apply-templates select="gl-cor:documentinfo"/> <xsl:call-template name="printpageheader"/> <xsl:apply-templates select="gl-cor:entryheader"/> <xsl:call-template name="printpagefooter"/> </xsl:template> <!-- gl-cor:entityinformation --> <xsl:template match="gl-cor:entityinformation"> <table style="width:100%; font-size:14px; font-weight:bold; margin-top:40px;"> <tbody> <tr> <td style="text-align:left; padding-bottom:20px;"> <span> <xsl:text>kurum unvanı : </xsl:text><xsl:value-of select="$unvan"/> </span> </td> <td style="text-align:right; font-size:16px;"> <span> <xsl:text>yevmİye defterİ</xsl:text> </span> </td> </tr> <tr> <td style="text-align:left; padding-bottom:20px;"> <span> <xsl:text>Şube adı: </xsl:text> <xsl:value-of select="$sube_adi"/> </span> </td> </tr> <tr> <td style="text-align:left; padding-top:10px;"> <span> <xsl:text>vergi no: </xsl:text><xsl:value-of select="$vkn"/> </span> </td> </tr> </tbody> </table> </xsl:template> <!-- gl-cor:documentinfo --> <xsl:template match="gl-cor:documentinfo"> <table style="width:100%; font-size:14px; font-weight:bold; margin-top:10px; margin-bottom:30px;"> <tbody> <tr> <td style="text-align:center; padding-top:10px;"> <span> <xsl:value-of select="gl-cor:entriescomment"/> </span> </td> </tr> </tbody> </table> </xsl:template> <!-- printpageheader --> <xsl:template name="printpageheader"> <table class="pageheader1"> <tbody> <tr> <td style="width:40%;"> <span> <xsl:text>yevmiye madde no</xsl:text> </span> </td> <td style="width:40%;"> <span> <xsl:text>yevmiye tarihi</xsl:text> </span> </td> <td style="width:300px; "/> </tr> </tbody> </table> <table class="pageheader2" > <tbody> <tr> <td style="width:155px;"> <span> <xsl:text>hesap kodu</xsl:text> </span> </td> <td style="width:2.28in;"> <span> <xsl:text>hesap adı</xsl:text> </span> <br/> </td> <td style="width:2.97in;"> <span> <xsl:text>açıklama</xsl:text> </span> </td> <td style="width:70px; "> <span> <xsl:text>borç </xsl:text> </span> </td> <td style="width:65px; "> <span> <xsl:text>alacak</xsl:text> </span> </td> </tr> <tr> <td style="width:155px; "> <span> <xsl:text> </xsl:text> </span> </td> <td style="width:2.28in; "> <span> <xsl:text> </xsl:text> </span> </td> <td style="width:2.97in; "> <span> <xsl:text> </xsl:text> </span> </td> <td style="width:70px; "> <span> <xsl:text> </xsl:text> </span> </td> <td style="width:65px; "> <span> <xsl:text> </xsl:text> </span> </td> </tr> </tbody> </table> </xsl:template> <!-- printpagefooter --> <xsl:template name="printpagefooter"> <hr width="100%" style="border: 1px dashed black;" color="#ffffff" size="6"/> <table style="border:0; font-style:normal; width:100%; margin-bottom:50px; " border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody> <tr style="font-style:normal; height:0.01in; "> <td style="width:50in; "/> <td style="text-align:right; width:10in; "> <span style="font-weight:bold; "> <xsl:text>borç toplamı :</xsl:text> </span> </td> <td style="width:11in; "/> <td style="text-align:right; width:5in; "> <span style="font-weight:bold; "> <xsl:variable name="debitsum"> <xsl:value-of select="format-number(number(sum(gl-cor:entryheader/gl-bus:totalcredit)), '###.##0,00', 'tryformat')"/> </xsl:variable> <xsl:value-of select="$debitsum"/> </span> </td> <td style="width:5in; "/> </tr> <tr style="font-style:normal; height:0.01in; "> <td style="width:50in;"/> <td style="width:10in;"/> <td style="text-align:right; width:11in; "> <span style="font-weight:bold; "> <xsl:text>alacak toplamı : </xsl:text> </span> </td> <td style="width:5in; "/> <td style="text-align:right; width:5in; "> <span style="font-weight:bold; "> <xsl:variable name="creditsum"> <xsl:value-of select="format-number(number(sum(gl-cor:entryheader/gl-bus:totaldebit)), '###.##0,00', 'tryformat')"/> </xsl:variable> <xsl:value-of select="$creditsum"/> </span> </td> </tr> </tbody> </table> </xsl:template> <!-- gl-cor:entryheader --> <xsl:variable name="pos" select="position()" /> <xsl:template match="gl-cor:entryheader"> <xsl:call-template name="printentryheaderheader"/> <xsl:apply-templates select="gl-cor:entrydetail"/> <xsl:call-template name="printentryheaderfooter"/> </xsl:template> <!-- printentryheaderheader --> <xsl:template name="printentryheaderheader"> <table class="entryheaderheader"> <xsl:result-document href="yevmiye{position()}.html" > <tr> <td> <div> <xsl:text>[ </xsl:text> <xsl:value-of select="gl-cor:entrynumbercounter"/> <xsl:text> ]</xsl:text> </div> <div/> </td> <td> <div> <xsl:text>[ </xsl:text> <xsl:call-template name="convertdate"> <xsl:with-param name="date" select="gl-cor:entereddate"/> </xsl:call-template> <xsl:text> ]</xsl:text> </div> <div/> </td> <td/> </tr> </xsl:result-document> </table> </xsl:template> <!-- gl-cor:entrydetail --> <xsl:template match="gl-cor:entrydetail"> <xsl:variable name="debitcreditnote" select="normalize-space(gl-cor:debitcreditcode)" /> <xsl:variable name="amount" select="format-number(number(gl-cor:amount), '###.##0,00', 'tryformat')"/> <xsl:variable name="documenttype" select="normalize-space(gl-cor:documenttype)"/> <table class="entrydetail"> <!-- print main acoount information --> <tr> <xsl:choose> <xsl:when test="$debitcreditnote = 'c' or $debitcreditnote = 'credit'"> <td style="width:30px;"/> </xsl:when> </xsl:choose> <td style="width:150px; font-weight:bold; padding-left:10px;"> <xsl:value-of select="gl-cor:account/gl-cor:accountmainid"/><xsl:text> </xsl:text> </td> <td style="font-weight:bold;"> <xsl:value-of select="gl-cor:account/gl-cor:accountmaindescription"/><xsl:text> </xsl:text> </td> <td style="width:100px; text-align:right; padding-right:20px;" > <xsl:choose> <xsl:when test="$debitcreditnote = 'd' or $debitcreditnote = 'debit'"> <xsl:value-of select="$amount"/> </xsl:when> </xsl:choose> </td> <td style="width:100px; text-align:right; padding-right:20px;" > <xsl:choose> <xsl:when test="$debitcreditnote = 'c' or $debitcreditnote = 'credit'"> <xsl:value-of select="$amount"/> </xsl:when> </xsl:choose> </td> </tr> <!-- print sub account information --> <xsl:choose> <xsl:when test="gl-cor:account/gl-cor:accountsub/gl-cor:accountsubid"> <tr> <xsl:choose> <xsl:when test="$debitcreditnote = 'c' or $debitcreditnote = 'credit'"> <td style="width:30px;"/> </xsl:when> </xsl:choose> <td style="width:150px; padding-left:10px;"> <xsl:value-of select="gl-cor:account/gl-cor:accountsub/gl-cor:accountsubid"/><xsl:text> </xsl:text> </td> <td> <xsl:value-of select="gl-cor:account/gl-cor:accountsub/gl-cor:accountsubdescription"/><xsl:text> </xsl:text> </td> </tr> </xsl:when> </xsl:choose> <!-- print payment method --> <xsl:choose> <xsl:when test="string-length(normalize-space(gl-bus:paymentmethod)) != 0 "> <tr style="font-size:8pt; font-style:italic;"> <xsl:choose> <xsl:when test="$debitcreditnote = 'c' or $debitcreditnote = 'credit'"> <td style="width:30px;"/> </xsl:when> </xsl:choose> <td style="width:150px;"/> <td> <span style="font-weight:bold;">Ödeme Şekli : </span><xsl:value-of select="gl-bus:paymentmethod"/> </td> </tr> </xsl:when> </xsl:choose> <!-- print document type, document number, document date --> <xsl:choose> <xsl:when test="string-length($documenttype) != 0" > <xsl:variable name="documentnumber" select="normalize-space(gl-cor:documentnumber)"/> <xsl:variable name="documentdate" select="normalize-space(gl-cor:documentdate)"/> <tr style="font-size:8pt; font-style:italic;"> <xsl:choose> <xsl:when test="$debitcreditnote = 'c' or $debitcreditnote = 'credit'"> <td style="width:30px;"/> </xsl:when> </xsl:choose> <td style="width:150px;"/> <td> <xsl:variable name="documentname"> <xsl:call-template name="finddocumenttype"> <xsl:with-param name="entrydetail" select="."/> </xsl:call-template> </xsl:variable> <xsl:choose> <xsl:when test="string-length($documentnumber) > 0 or string-length($documentdate) > 0"> <xsl:choose> <xsl:when test="string-length($documentnumber) > 0 "> <span style="font-weight:bold;"><xsl:value-of select="$documentname"/> no : </span><xsl:value-of select="$documentnumber"/> <xsl:text> </xsl:text> </xsl:when> </xsl:choose> <xsl:choose> <xsl:when test="string-length($documentdate) > 0 "> <span style="font-weight:bold;"><xsl:value-of select="$documentname"/> tarihi : </span> <xsl:call-template name="convertdate"> <xsl:with-param name="date" select="$documentdate"/> </xsl:call-template> </xsl:when> </xsl:choose> </xsl:when> <xsl:otherwise> <span style="font-weight:bold;">belge türü : </span><xsl:value-of select="$documentname"/> </xsl:otherwise> </xsl:choose> </td> </tr> </xsl:when> </xsl:choose> </table> </xsl:template> <!-- printentryheaderfooter --> <xsl:template name="printentryheaderfooter"> <div class="entryheaderfooter"> <xsl:value-of select="gl-cor:entrycomment"/> <br/> <xsl:text>muhasebe fiş no : </xsl:text> <xsl:value-of select="gl-cor:entrynumber"/> </div> </xsl:template> <xsl:template name="convertdate"> <xsl:param name="date"/> <xsl:value-of select="concat(substring($date,9,2),'/', substring($date, 6,2), '/', substring($date,1,4))"/> </xsl:template> <xsl:template name="finddocumenttype"> <xsl:param name="entrydetail"/> <xsl:choose> <xsl:when test="$entrydetail/gl-cor:documenttype = 'check'"> <xsl:text>Çek </xsl:text> </xsl:when> <xsl:when test="$entrydetail/gl-cor:documenttype = 'invoice'"> <xsl:text>fatura</xsl:text> </xsl:when> <xsl:when test="$entrydetail/gl-cor:documenttype = 'order-customer'"> <xsl:text>müşteri siparişi</xsl:text> </xsl:when> <xsl:when test="$entrydetail/gl-cor:documenttype = 'order-vendor'"> <xsl:text>satıcı siparişi</xsl:text> </xsl:when> <xsl:when test="$entrydetail/gl-cor:documenttype = 'voucher'"> <xsl:text>senet</xsl:text> </xsl:when> <xsl:when test="$entrydetail/gl-cor:documenttype = 'shipment'"> <xsl:text>navlun</xsl:text> </xsl:when> <xsl:when test="$entrydetail/gl-cor:documenttype = 'receipt'"> <xsl:text>makbuz</xsl:text> </xsl:when> <xsl:otherwise> <xsl:value-of select="$entrydetail/gl-cor:documenttypedescription"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
below xsl code taken above xsl want split
<!-- printentryheaderheader --> <xsl:template name="printentryheaderheader"> <table class="entryheaderheader"> <xsl:result-document href="yevmiye{position()}.html" > <tr> <td> <div> <xsl:text>[ </xsl:text> <xsl:value-of select="gl-cor:entrynumbercounter"/> <xsl:text> ]</xsl:text> </div> <div/> </td> <td> <div> <xsl:text>[ </xsl:text> <xsl:call-template name="convertdate"> <xsl:with-param name="date" select="gl-cor:entereddate"/> </xsl:call-template> <xsl:text> ]</xsl:text> </div> <div/> </td> <td/> </tr> </xsl:result-document> </table> </xsl:template>
the usual approach use positional grouping , result-document
e.g.
<xsl:for-each-group select="//entryheaderheader" group-adjacent="position() idiv 1000"> <xsl:result-document href="chunk{position()}.html"> <html> <body> <table> <xsl:apply-templates select="current-group()"/> </table> </body> </html> </xsl:result-document> </xsl:for-each-group>
Comments
Post a Comment