tags:

views:

25

answers:

2

Hi how to convert the following empty element tag in the following xml

 <LIST_R7P1_1>
 <R7P1_1>
  <ORIG_EXP_PRE_CONV /> 
  <EXP_AFT_CONV /> 
  <GUARANTEE_AMOUNT /> 
  <CREDIT_DER /> 
 </R7P1_1>
 </LIST_R7P1_1>

to the following format using xslt

 <LIST_R7P1_1>
 <R7P1_1>
  <ORIG_EXP_PRE_CONV >0<ORIG_EXP_PRE_CONV /> 
  <EXP_AFT_CONV >0<EXP_AFT_CONV /> 
  <GUARANTEE_AMOUNT >0<GUARANTEE_AMOUNT /> 
  <CREDIT_DER >0<CREDIT_DER /> 
 </R7P1_1>
 </LIST_R7P1_1>
A: 

Since you didn't post any of your own code (i.e. what you have already tried) I'll tell you how to solve the problem without giving you the code: Google "XSL identity transform", then add some specific templates for the tags you want to change. The specific templates will need to "copy" the input nodes and their attributes while adding a text child node.

Jim Garrison
Actually I am adding some elements and sum are empty elements in that set of elements for which I am getting null value in the sum . I was thinking if I convert the <CREDIT_DER /> to <CREDIT_DER>0</CREDIT_DER> then getting sum of the elements would be easy for me. If you know any other process the please share it with me
A: 

This stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="*[not(node())]">
        <xsl:copy>0</xsl:copy>
    </xsl:template>
</xsl:stylesheet>

With this input:

<LIST_R7P1_1>
    <R7P1_1>
        <ORIG_EXP_PRE_CONV />
        <EXP_AFT_CONV />
        <GUARANTEE_AMOUNT></GUARANTEE_AMOUNT>
        <CREDIT_DER></CREDIT_DER>
    </R7P1_1>
</LIST_R7P1_1>

Output:

<LIST_R7P1_1>
    <R7P1_1>
        <ORIG_EXP_PRE_CONV>0</ORIG_EXP_PRE_CONV>
        <EXP_AFT_CONV>0</EXP_AFT_CONV>
        <GUARANTEE_AMOUNT>0</GUARANTEE_AMOUNT>
        <CREDIT_DER>0</CREDIT_DER>
    </R7P1_1>
</LIST_R7P1_1>

But, with the same input, this XPath expresion:

sum(/LIST_R7P1_1/R7P1_1/*/text())

Result:

0
Alejandro