TESTCASESTARTTIME to time TESTCASENAME to name HTMLLOGFILENAME to url RESULT to status I need these 4 attributes to be changed
You need to exclude these 4 elements from the generic xsl:for-each
applied to the other elements, and handle them explicitly:
XSLT 1.0
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="TESTSEQUENCE">
<testcase>
<xsl:for-each select="*[not (self::TESTCASESTARTTIME or self::TESTCASENAME or self::HTMLLOGFILENAME or self::RESULT)]">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:attribute name="time">
<xsl:value-of select="TESTCASESTARTTIME"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="TESTCASENAME"/>
</xsl:attribute>
<xsl:attribute name="url">
<xsl:value-of select="HTMLLOGFILENAME"/>
</xsl:attribute>
<xsl:attribute name="status">
<xsl:value-of select="RESULT"/>
</xsl:attribute>
</testcase>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Applied to your example input of:
<TESTSEQUENCE>
<TESTCASESTARTTIME>2014-05-02 16:02:38</TESTCASESTARTTIME>
<TESTCASENAME>TRAFFIC_MIXED_COLD_TP-A15</TESTCASENAME>
<SCRIPTFILENAME>/proj/cpptemp/dt/network_repo/398/int/IEXS_CRX901185_1/iov/cbm1-3_mct/tc/Traffic.tcl</SCRIPTFILENAME>
<TXTLOGFILENAME>TRAFFIC_MIXED_COLD_TP-A15/TRAFFIC_MIXED_COLD_TP-A15.txt</TXTLOGFILENAME>
<HTMLLOGFILENAME>TRAFFIC_MIXED_COLD_TP-A15.html</HTMLLOGFILENAME>
<XMLLOGFILENAME>TRAFFIC_MIXED_COLD_TP-A15.xml</XMLLOGFILENAME>
<STARTTIME>1399039358</STARTTIME>
<TOTALCMDS>27</TOTALCMDS>
<NOTOKIDS>27</NOTOKIDS>
<NOTOKCMDS>{CETP ABORT}</NOTOKCMDS>
<FAILURESTRINGS>1=Failed,</FAILURESTRINGS>
<RESULT>ABORTED</RESULT>
<FINISHTIME>1399039672</FINISHTIME>
</TESTSEQUENCE>
the result is:
<?xml version="1.0" encoding="UTF-8"?>
<testcase SCRIPTFILENAME="/proj/cpptemp/dt/network_repo/398/int/IEXS_CRX901185_1/iov/cbm1-3_mct/tc/Traffic.tcl" TXTLOGFILENAME="TRAFFIC_MIXED_COLD_TP-A15/TRAFFIC_MIXED_COLD_TP-A15.txt" XMLLOGFILENAME="TRAFFIC_MIXED_COLD_TP-A15.xml" STARTTIME="1399039358" TOTALCMDS="27" NOTOKIDS="27" NOTOKCMDS="{CETP ABORT}" FAILURESTRINGS="1=Failed," FINISHTIME="1399039672" time="2014-05-02 16:02:38" name="TRAFFIC_MIXED_COLD_TP-A15" url="TRAFFIC_MIXED_COLD_TP-A15.html" status="ABORTED"/>