Skip navigation

India User Group

2 Posts authored by: prabhu deva
Share:|

HI Team,

 

  1. I have designed a simple XSLT to remove the extra empty lines and empty space  in a string. Please use the below during string transformation J

 

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />

  <xsl:template match="@*|node()">

    <xsl:copy>

      <xsl:apply-templates select="@*|node()" />

    </xsl:copy>

  </xsl:template>

  <xsl:template match="value/text()" name="tokenize">

    <xsl:param name="text" select="." />

    <xsl:param name="separator" select="'&#xA;'" />

    <xsl:choose>

      <xsl:when test="not(contains($text, $separator))">

<xsl:value-of select="normalize-space($text)" />

      </xsl:when>

      <xsl:otherwise>

<xsl:value-of select="normalize-space(substring-before($text, $separator))" />

        <xsl:if test="substring-before($text, $separator) != ''">

<xsl:value-of select=" $separator"/>

</xsl:if>

<xsl:call-template name="tokenize">

<xsl:with-param name="text" select="substring-after($text, $separator)" />

</xsl:call-template>

      </xsl:otherwise>

    </xsl:choose>

  </xsl:template>

</xsl:stylesheet>

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

Filter Blog

By date:
By tag: