开发者

why applied template is repeating twice

hi i have applied a template data should to be populate only once, here issue was it was repeating twice can any one suggest to stop that repeatation find the below my sample code of xsl

Here is my XSL:

   <xsl:param name="PackageId"  />
  <xsl:template match="/">      
    <xsl:apply-templates mode="SequenceB"  select="NewDataSet/Table[CTD_CTD_PKG_ID =$PackageId]"/>
    <xsl:apply-templates mode="sequenceC"  select="NewDataSet/Table[CTD_CTD_PKG_ID =$PackageId][position()=1]"/>
</xsl:template>
 <xsl:template mode ="SequenceB" match="NewDataSet/Table">

    <xsl:choose >

          <xsl:when  test ="substring(./MSG_TYPE_CODE,2,3)= '102'"  >

                <xsl:if test ="./CTD_SEQ_NUM"  >
                    <xsl:if test=" position() &gt; 1"></xsl:if>
                    <xsl:value-of select= "concat(':21:',./CTD_SEQ_NUM)" />
                    <xsl:text>&#13;</xsl:text >
                </xsl:if>
              <xsl:if test ="./CURRENCY_CODE" >
                  <xsl:if test=" position() &gt; 1"></xsl:if>
                  <xsl:text/><xsl:value-of select= "concat(':32B:',./CURRENCY_CODE)"/>

              </xsl:if>
             开发者_高级运维 <xsl:if test ="./CTD_SETLD_TRAN_AMT" >
                  <xsl:if test=" position() &gt; 1"></xsl:if>
                  <xsl:text/><xsl:value-of select= "translate(./CTD_SETLD_TRAN_AMT ,'.',',')"/>
                  <xsl:text>&#13;</xsl:text >
              </xsl:if>
        </xsl:when>
    <xsl:when test ="substring(./MSG_TYPE_CODE,2,3)= '103'">
            <xsl:if test ="./TRAN_TYPE_CODE"  >
                <xsl:text/><xsl:value-of select=           "concat(':26T:',./TRAN_TYPE_CODE)" /><xsl:text/>
            </xsl:if>
            <xsl:if test ="./CTD_VALUE_DATE" >
                <xsl:text/><xsl:value-of select= "concat(':32A:',./CTD_VALUE_DATE)"/><xsl:text/>
            </xsl:if>
            <xsl:if test ="./CURRENCY_CODE" >
                <xsl:text/><xsl:value-of select= "./CURRENCY_CODE"/><xsl:text/>
            </xsl:if>
            <xsl:if test ="./CTD_SETLD_TRAN_AMT" >
                <xsl:text/><xsl:value-of select= "translate(./CTD_SETLD_TRAN_AMT,'.',',')"/><xsl:text/>
            </xsl:if>
      </xsl:when>
           </xsl:choose>
</xsl:template> 

     <xsl:template mode="sequenceC" match="NewDataSet/Table">

    <xsl:if test ="substring(./MSG_TYPE_CODE,2,3)= '102'">

    <xsl:if test ="./CTD_VALUE_DATE" >
        <xsl:text/><xsl:value-of select= "concat(':32A:',./CTD_VALUE_DATE)"/><xsl:text/>
    </xsl:if>
    <xsl:if test ="./CURRENCY_CODE" >
        <xsl:text/><xsl:value-of select= "./CURRENCY_CODE"/><xsl:text/>
    </xsl:if>
    <xsl:if test ="./CTD_SETLD_TRAN_AMT" >
        <xsl:text/><xsl:value-of select= "translate(./CTD_SETLD_TRAN_AMT,'.',',')"/>
        <xsl:text>&#13;</xsl:text >
    </xsl:if>
     </xsl:template>

Here is my XML:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Table>
  <RECORD_TYPE_CODE>CTD</RECORD_TYPE_CODE>
  <MSG_TYPE_CODE>O102N</MSG_TYPE_CODE>
  <CTD_SEQ_NUM>000001</CTD_SEQ_NUM>
  <CTD_BEN_INS_ID>ABNAAEAD</CTD_BEN_INS_ID>
  <TRAN_TYPE_CODE>MIS</TRAN_TYPE_CODE>
  <CTD_VALUE_DATE>110911</CTD_VALUE_DATE>
  <CURRENCY_CODE>AED</CURRENCY_CODE>
  <CTD_SETLD_TRAN_AMT>42404.00</CTD_SETLD_TRAN_AMT>
  <CTD_INS_AMT>42404.00</CTD_INS_AMT>
  <CTD_CTD_PKG_ID>2</CTD_CTD_PKG_ID>    
 </Table>
 <Table>
  <RECORD_TYPE_CODE>CTD</RECORD_TYPE_CODE>
  <MSG_TYPE_CODE>O102N</MSG_TYPE_CODE>
  <CTD_SEQ_NUM>000002</CTD_SEQ_NUM>
 <CTD_BEN_INS_ID>ABNAAEAD</CTD_BEN_INS_ID>
 <TRAN_TYPE_CODE>MIS</TRAN_TYPE_CODE>
 <CTD_VALUE_DATE>110911</CTD_VALUE_DATE>
 <CURRENCY_CODE>AED</CURRENCY_CODE>
 <CTD_SETLD_TRAN_AMT>154776.75</CTD_SETLD_TRAN_AMT>
 <CTD_INS_AMT>154776.75</CTD_INS_AMT>
 <CTD_CTD_PKG_ID>2</CTD_CTD_PKG_ID>    
 </Table>
<Table>
<RECORD_TYPE_CODE>CTD</RECORD_TYPE_CODE>
<MSG_TYPE_CODE>O102N</MSG_TYPE_CODE>
<CTD_SEQ_NUM>000003</CTD_SEQ_NUM>
<CTD_BEN_INS_ID>ABNAAEAD</CTD_BEN_INS_ID>
<TRAN_TYPE_CODE>MIS</TRAN_TYPE_CODE>
<CTD_VALUE_DATE>110911</CTD_VALUE_DATE>
<CURRENCY_CODE>AED</CURRENCY_CODE>
<CTD_SETLD_TRAN_AMT>1800.00</CTD_SETLD_TRAN_AMT>
   <CTD_INS_AMT>1800.00</CTD_INS_AMT>
<CTD_CTD_PKG_ID>2</CTD_CTD_PKG_ID>    
      </Table>
      </NewDataSet>

output:

:21:000001 :32B:AED42404,00 :21:000001 :32B:AED42404,00 :21:000002 :32B:AED154776,75 :21:000002 :32B:AED154776,75 :21:000003 :32B:AED1800,00 :21:000003 :32B:AED1800,00 :32A:110911AED42404,00

required output as :

:21:000001 :32B:AED42404,00 :21:000002 :32B:AED154776,75 :21:000003 :32B:AED1800,00 :32A:110911AED42404,00


In your first template you have several times the following line:

<xsl:if test=" position() &gt; 1"></xsl:if>

This line doesn't do anything, code that is to be executed only when the condition is true should go between the tags (as you have done in other places).

Similarly, you have this kind of stuff in a few places:

<xsl:text/><xsl:value-of select= "./CURRENCY_CODE"/><xsl:text/>

The text tags serve no purpose as they are auto closing.

You should make a round of clean up on the opening/closing of all the tags. Even if the problem does not disappear, it will be a lot easier to analyze.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜