Share This:

Hi All,

I faced an error named Premature end of file in XSLT transformation of XML, which was caused by the following reason.

1. I forgot to add the start and end of Root element before For loop.

Following XSLT is for grouping the transactions which has same branch code.


in the following XSLT tag <body> was not present at first. once I add it the issue got resolved.






  <xsl:output indent="yes" />

  <xsl:template match="value">


      <xsl:for-each select="Transaction">

    <xsl:sort select="Branch_Code" />

        <xsl:variable name="b" select="Branch_Code"/>

        <xsl:if test="not(preceding-sibling::*[Branch_Code = $b])">



               <xsl:value-of select="Branch_Code"/>



  <xsl:value-of select="Email_Recipients"/>


           <xsl:for-each select="/value/Transaction[Branch_Code=$b]">

                <xsl:sort select="Branch_Code"/>



   <xsl:value-of select="Tran_No"/>



   <xsl:value-of select="Error_Description"/>











To Avoid the premature End of fie, every resulting XML must have a Root element