开发者

How to assign value to empty element tags in xml(self closed elements) using XSLT

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>


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.


This stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜