开发者

xslt problem issue

hi all i m having one xml like bellow

<NewDataSet>
    <Table>
        <CTD_REC_TYPE_ID>5</CTD_REC_TYPE_ID> 
        <CTD_BEN_INS_ID>0048201515</CTD_BEN_INS_ID> 
        <CTD_CURR_CODE>2</CTD_CURR_CODE> 
        <CTD_ORD_CUST_ACT>CACC</CTD_ORD_CUST_ACT> 
        <CTD_CTD_PKG_ID>6</CTD_CTD_PKG_ID> 
    </Table>
    <Table>
        <CTD_REC_TYPE_ID>5</CTD_REC_TYPE_ID> 
        <CTD_BEN_INS_ID>004820101</CTD_BEN_INS_ID> 
        <CTD_CURR_CODE>2</CTD_CURR_CODE> 
        <CTD_ORD_CUST_ACT>CACC</CTD_ORD_CUST_ACT> 
        <CTD_CTD_PKG_ID>6</CTD_CTD_PKG_ID> 
    </Table>
    <Table>
        <CTD_REC_TYPE_ID>5</CTD_REC_TYPE_ID> 
        <CTD_BEN_INS_ID>004820101</CTD_BEN_INS_ID> 
        <CTD_CURR_CODE>2</CTD_CURR_CODE> 
        &l开发者_StackOverflow中文版t;CTD_ORD_CUST_ACT>CACC</CTD_ORD_CUST_ACT> 
        <CTD_CTD_PKG_ID>3</CTD_CTD_PKG_ID> 
    </Table>
</NewDataSet>

in the above xml every table have to concentrate <CTD_CTD_PKG_ID>3</CTD_CTD_PKG_ID> (package id ) as if above example we are having three table in that xml when coming to pkg id 6,6,3 six was repeated two time for that i have concatenate that two similar table and make as one csv file and rest other pkg id for 3 we have prepare seperate csv file so that we need to write xslt can any one help me please ....asap


If you need n different output files you will need to run your transformation n times, each time with the desired <CTD_CTD_PKG_ID> value as a filter parameter.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" indent="no" omit-xml-declaration="yes" />

    <!-- sample value hardcoded here for demonstration -->
    <xsl:param name="filterid" select="3" />

    <!--
        for implementation just declare param
        <xsl:param name="filterid" />
    -->

    <xsl:template match="/">
        <xsl:apply-templates />
    </xsl:template>

    <xsl:template match="NewDataSet">
        <xsl:for-each select="Table[CTD_CTD_PKG_ID = $filterid]">
            <xsl:text/><xsl:value-of select="./CTD_REC_TYPE_ID"/>;<xsl:text/>
            <xsl:text/><xsl:value-of select="./CTD_BEN_INS_ID"/>;<xsl:text/>
            <xsl:text/><xsl:value-of select="./CTD_CURR_CODE"/>;<xsl:text/>
            <xsl:text/><xsl:value-of select="./CTD_ORD_CUST_ACT"/>;<xsl:text/>
            <xsl:text/><xsl:value-of select="./CTD_CTD_PKG_ID"/><xsl:text/>
            <xsl:text>&#13;</xsl:text>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

How you go about to pass the param value for filterid depends on the transformation engine you are using.

If using this Xslt on the sample Xml data you will receive

5;004820101;2;CACC;3

as your result.

If you set <xsl:param name="filterid" select="6" /> you will receive

5;0048201515;2;CACC;6
5;004820101;2;CACC;6

See XslCompiledTransform.Transform with XsltArgumentList for reference on how to submit a parameter to a Xslt using the .NET framework.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜