Display Serial number using XSLT

teptCreagma

New Member
My input XML consists of the following,\[code\]<root> <entry> <type>U</type> <value>111</value> </entry> <entry> <type>X</type> <value>222</value> </entry> <entry> <type>E</type> <value>333</value> </entry> <entry> <type>Q</type> <value>444</value> </entry> <entry> <value>555</value> </entry> <entry> <value>666</value> </entry></root>\[/code\]Output i required,\[code\]<ROOT> <ENTRY> <SLNO>1</SLNO> <VALUE>111</VALUE> </ENTRY> <ENTRY> <SLNO>1</SLNO> <VALUE>222</VALUE> </ENTRY> <ENTRY> <SLNO>1</SLNO> <VALUE>333</VALUE> </ENTRY> <ENTRY> <SLNO>2</SLNO> <VALUE>444</VALUE> </ENTRY> <ENTRY> <SLNO>3</SLNO> <VALUE>555<VALUE> </ENTRY> <ENTRY> <SLNO>4</SLNO> <VALUE>666</VALUE> </ENTRY></ROOT>\[/code\]The requirement is to generate new SLNO for types other than X, E, Y and K and also if type tag itself is missing. For all other types we need to display new serial number.I have written a for-each to for the same since i have to do some more processing with another values, so for-each is a must.How can I achieve this?My sample XSL code is asl follows,\[code\]<xsl:for-each select="/ROOT/ENTRY"> <xsl:if test="(TYPE != 'X') and (TYPE != 'E')"> <xsl:text><![CDATA[<SLNO>]]></xsl:text> <xsl:if test="((type != 'X') and (type != 'E') and (type != 'Y') and (type != 'K'))"> <xsl:value-of select="count(preceding::type[((. != 'X' and . != 'E' and . != 'Y' and . !='K') or . ='')]) + 1" /> </xsl:if> <xsl:if test="(type = 'X') or (type = 'E') or (type = 'Y') or (type = 'K')"> <xsl:value-of select="count(preceding::type[(. != 'X' and . != 'E' and . != 'Y' and . !='K')])" /> </xsl:if> <xsl:text><![CDATA[</SLNO>]]></xsl:text> </xsl:if> <!-- Printing remaining values --></xsl:for-each>\[/code\]Problem with this code is, i'm not getting SLNO for entries that does not have type tag.Please help.
 
Back
Top