开发者

Simple way to write XSLT for the XML listed

I have a complex xml. (only some part has been shown here). How simple my XSLT can be to display the following output.

Input XML

<?xml version="1.0" encoding="UTF-8"?>
 <FINALDATA CPCreatedDate_UTC="2012-4-3 16:45:36.187">
<SOLUTIONS>
    <PROBLEMCAUSE Key="41607CD1-1B0F-45FA-B0DF-FACBCBBFCD19">thermocouple harness
        <SOLUTION>
            <ID>2060000000开发者_运维百科0000000000000000000001</ID>
            <MESSEAGE Key="1342F86E-6D34-429D-AE09-C71DB1933206">Broken wire</MESSEAGE>
        </SOLUTION>
    </PROBLEMCAUSE>
    <PROBLEMCAUSE Key="7C6534BE-CEA5-4BD7-8C38-C2D51B72FA42">thermocouple data
        <SOLUTION>
            <ID>20600000000000000000000000000002</ID>
            <MESSEAGE Key="DCA8E42A-BCD2-431F-87FA-9485F1B23C9E">Pump Value</MESSEAGE>
        </SOLUTION>
    </PROBLEMCAUSE>
 </SOLUTIONS>
</FINALDATA>

Output XML (Required)

<Delta>
<Package Time = "2012-4-3 16:45:36.187" >
        <Entities>
        <FailDatas>
            <FailData>thermocouple harness</FailData>
            <FailData>thermocouple data</FailData>  
        </FailDatas>
        <Messages>
            <Message>Broken wire</Message>
            <Message>Pump Value</Message>   
        </Messages>
    </Entities>
    <Relationships>
    </Relationships>
    <Relationships></Relationships>
</Package>
</Delta>

All this i have to do based on the Key value listed above. Please help me in forming this.

Thanks Ramm


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" />

    <xsl:template match="*"/>

    <xsl:template match="FINALDATA">
        <Delta>
                <Package Time="{@CPCreatedDate_UTC}">
            <xsl:apply-templates select="@*|node()" />
               </Package>
        </Delta>
    </xsl:template>

    <xsl:template match="SOLUTIONS">
        <Entities>
            <FailDatas>
                <xsl:apply-templates select="PROBLEMCAUSE"/>
            </FailDatas>
            <Messages>
                <xsl:apply-templates select="PROBLEMCAUSE/SOLUTION/MESSEAGE"/>
            </Messages>
            <xsl:apply-templates select="PROBLEMCAUSE" mode="Relationships" />
        </Entities>
    </xsl:template>

    <xsl:template match="PROBLEMCAUSE">
        <FailData>
            <xsl:value-of select="normalize-space(text())"/>
        </FailData>
    </xsl:template>

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

    <xsl:template match="PROBLEMCAUSE" mode="Relationships">
        <Relationships />
    </xsl:template>

</xsl:stylesheet>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜