Share:|

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:stylesheet

  version="1.0"

  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

>

  <xsl:output indent="yes" />

  <xsl:template match="value">

    <body>

      <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])">

  <Transaction>

            <Branch_Code>

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

           </Branch_Code>

  <Email_Recipients>

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

  </Email_Recipients>

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

                <xsl:sort select="Branch_Code"/>

    <Items>

  <Tran_No>

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

  </Tran_No>

  <Error_Description>

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

  </Error_Description>

    </Items>

             </xsl:for-each>

    </Transaction>

         </xsl:if>

      </xsl:for-each>

    </body>

  </xsl:template>

</xsl:stylesheet>

 

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