xml - Increment a particular exported HTML tag via XSL -


i trying export xml html information can presented in nice tabular format. part of xsl

<xsl:template match="step">     <tr>         <xsl:choose>             <xsl:when test="starts-with(obj, '▬▬ uc_')">                 <td>numbering here</td>                 <td class="level0">                     <xsl:value-of select="obj" disable-output-escaping="no" />                 </td>             </xsl:when>             <xsl:otherwise>                 <td></td>                 <td class="level{count(ancestor::*)-3}">                     <xsl:value-of select="obj" disable-output-escaping="no" />                 </td>             </xsl:otherwise>         </xsl:choose>         <td>             <pre>                 <xsl:value-of select="details" disable-output-escaping="no" />             </pre>         </td>     <xsl:apply-templates select="step"/> </xsl:template> 

basically, want if obj's td level0, want insert numbering (1,2,3,4,etc) in previous td. understand xsl variables read only, there way can put increment numbers each <td class="level0"> ?

sample xml

<action rid="t4">     <step rid="t5">         <obj><![cdata[▬▬ uc_p1_bond_010 ▬▬]]></obj>         <details><![cdata[product = multiple; event = new]]></details>         <time><![cdata[01/04/2015 - 10:43:54]]></time>         <timetick>1427881434</timetick>         <nodeargs etype="user" icon="5" nrep="8" source="action1" sourceline="-1">             <disp><![cdata[▬▬ uc_p1_bond_010 ▬▬]]></disp>         </nodeargs>     </step>     <step rid="t6">         <obj><![cdata[●●● td_setupbond]]></obj>         <details><![cdata[executing script steps of td_setupbond]]></details>         <time><![cdata[01/04/2015 - 10:43:54]]></time>         <timetick>1427881434</timetick>         <nodeargs etype="user" icon="5" nrep="9" source="action1" sourceline="-1">             <disp><![cdata[●●● td_setupbond]]></disp>         </nodeargs>     </step>     <step rid="t7">         <obj><![cdata[statement skipped: #newamend]]></obj>         <details><![cdata[0]]></details>         <time><![cdata[01/04/2015 - 10:43:55]]></time>         <timetick>1427881435</timetick>         <nodeargs etype="user" icon="5" nrep="10" source="action1" sourceline="-1">             <disp><![cdata[statement skipped: #newamend]]></disp>         </nodeargs>     </step>     <step rid="t8">         <obj><![cdata[statement skipped: #outbound]]></obj>         <details><![cdata[2]]></details>         <time><![cdata[01/04/2015 - 10:43:55]]></time>         <timetick>1427881435</timetick>         <nodeargs etype="user" icon="5" nrep="11" source="action1" sourceline="-1">             <disp><![cdata[statement skipped: #outbound]]></disp>         </nodeargs>     </step>     <step rid="t9">         <obj><![cdata[●●● td_verifybondnewamend]]></obj>         <details><![cdata[executing script steps of td_verifybondnewamend]]></details>         <time><![cdata[01/04/2015 - 10:44:01]]></time>         <timetick>1427881441</timetick>         <nodeargs etype="user" icon="5" nrep="12" source="action1" sourceline="-1">             <disp><![cdata[●●● td_verifybondnewamend]]></disp>         </nodeargs>     </step>     <step rid="t10">         <obj plaintxt="false"><![cdata[home window]]></obj>         <details plaintxt="false"><![cdata[javawindow]]></details>         <time><![cdata[01/04/2015 - 10:44:01]]></time>         <timetick>1427881441</timetick>         <step rid="t11">             <obj plaintxt="false"><![cdata[quick search.click]]></obj>             <details plaintxt="false"><![cdata["left"]]></details>             <time><![cdata[01/04/2015 - 10:44:01]]></time>             <timetick>1427881441</timetick>             <nodeargs etype="replay" icon="7" nrep="15" source="action1" sourceline="-1">                 <disp><![cdata[quick search.click]]></disp>             </nodeargs>         </step>         <nodeargs etype="context" icon="6" nrep="14" source="action1" sourceline="-1">             <disp><![cdata[home window]]></disp>         </nodeargs>     </step>     <step rid="t160">         <obj><![cdata[▬▬ uc_p1_bond_011 ▬▬]]></obj>         <details><![cdata[product multiple; event = amend]]></details>         <time><![cdata[01/04/2015 - 10:45:14]]></time>         <timetick>1427881514</timetick>         <nodeargs etype="user" icon="5" nrep="972" source="action1" sourceline="-1">             <disp><![cdata[▬▬ uc_p1_bond_011 ▬▬]]></disp>         </nodeargs>     </step>     <step rid="t161">         <obj><![cdata[●●● td_setupbond]]></obj>         <details><![cdata[executing script steps of td_setupbond]]></details>         <time><![cdata[01/04/2015 - 10:45:14]]></time>         <timetick>1427881514</timetick>         <nodeargs etype="user" icon="5" nrep="973" source="action1" sourceline="-1">             <disp><![cdata[●●● td_setupbond]]></disp>         </nodeargs>     </step>     <step rid="t162">         <obj><![cdata[statement skipped: #newamend]]></obj>         <details><![cdata[0]]></details>         <time><![cdata[01/04/2015 - 10:45:14]]></time>         <timetick>1427881514</timetick>         <nodeargs etype="user" icon="5" nrep="974" source="action1" sourceline="-1">             <disp><![cdata[statement skipped: #newamend]]></disp>         </nodeargs>     </step>     <step rid="t163">         <obj><![cdata[statement skipped: #outbound]]></obj>         <details><![cdata[2]]></details>         <time><![cdata[01/04/2015 - 10:45:14]]></time>         <timetick>1427881514</timetick>         <nodeargs etype="user" icon="5" nrep="975" source="action1" sourceline="-1">             <disp><![cdata[statement skipped: #outbound]]></disp>         </nodeargs>     </step>     <step rid="t164">         <obj><![cdata[●●● td_verifybondnewamend]]></obj>         <details><![cdata[executing script steps of td_verifybondnewamend]]></details>         <time><![cdata[01/04/2015 - 10:45:20]]></time>         <timetick>1427881520</timetick>         <nodeargs etype="user" icon="5" nrep="976" source="action1" sourceline="-1">             <disp><![cdata[●●● td_verifybondnewamend]]></disp>         </nodeargs>     </step>     <step rid="t165">         <obj plaintxt="false"><![cdata[home window]]></obj>         <details plaintxt="false"><![cdata[javawindow]]></details>         <time><![cdata[01/04/2015 - 10:45:21]]></time>         <timetick>1427881521</timetick>         <step rid="t166">             <obj plaintxt="false"><![cdata[quick search.click]]></obj>             <details plaintxt="false"><![cdata["left"]]></details>             <time><![cdata[01/04/2015 - 10:45:21]]></time>             <timetick>1427881521</timetick>             <nodeargs etype="replay" icon="7" nrep="979" source="action1" sourceline="-1">                 <disp><![cdata[quick search.click]]></disp>             </nodeargs>         </step>     </step>     .     .     .     , on </action> 

sample html output

enter image description here

let have minimized example:

xml

<action rid="t4">     <step rid="t5">         <obj><![cdata[▬▬ uc_a]]></obj>     </step>     <step rid="t6">         <obj><![cdata[abc]]></obj>     </step>     <step rid="t7">         <obj><![cdata[bcd]]></obj>     </step>     <step rid="t8">         <obj><![cdata[cde]]></obj>     </step>     <step rid="t9">         <obj><![cdata[▬▬ uc_b]]></obj>     </step>     <step rid="t10">         <obj><![cdata[def]]></obj>     </step>     <step rid="t11">         <obj><![cdata[efg]]></obj>     </step> </action> 

xslt 1.0

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>  <xsl:template match="/action">     <table border="1">         <xsl:apply-templates/>       </table> </xsl:template>  <xsl:template match="step">     <tr>         <td>             <xsl:if test="starts-with(obj, '▬▬ uc_')">                 <xsl:number count="step[starts-with(obj, '▬▬ uc_')]"/>             </xsl:if>         </td>         <td>             <xsl:value-of select="obj" />         </td>     </tr> </xsl:template>  </xsl:stylesheet> 

output (rendered)

enter image description here


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -