Hi All

I'm a newbie at XSLT and I need help to do the following. I am trying to transform the attached XML so it inserts a blank row whenever the current account number(curACCTNO) does not equal the previous account (preACCTNO) number i.e. group similar rows with the same accno but insert blank row where different.

I think I know what do to once I can get the current and previous values. Getting to those is whats killing me. If anyone can help on this I would really really appreciate it! If I haven't explained properly please let me know.

I currently have the following but not sure how to drill down to the actual value.

Thanks in advance!

<xsl:for-each select="tr">
	     <xsl:variable name="prevRowPos" select="(position()-1)"/>
	     <xsl:variable name="currRowPos" select="position()"/>
<reports>
	<report>
		<info>
			<file-name>40097.xml</file-name>
			<status>0</status>
			<report-id>5</report-id>
			<columns>
				<col name="UTILNAME" type="str"/>
				<col name="SITE_NAME" type="str"/>
				<col name="RATECODE1" type="str"/>
				<col name="ACCTADR1" type="str"/>
				<col name="ACCTCITY" type="str"/>
				<col name="ACCTSTATE" type="str"/>
				<col name="ACCTZIP" type="str"/>
				<col name="FAC_STATUS" type="str"/>
				<col name="ACCT_STATUS" type="str"/>
				<col name="SERVICE_TERM_DATE" type="date"/>
				<col name="ACCTNO" type="str"/>
				<col name="COMMODITYID" type="str"/>
				<col name="CSMTNPER" type="date"/>
				<col name="STARTDATE" type="date"/>
				<col name="STOPDATE" type="date"/>
				<col name="BILLSRVID" type="int"/>
				<col name="MTRNO" type="str"/>
etc...
			</columns>
		</info>
		<data>
			<tr>
				<td>Electric Co</td>
				<td>0042</td>
				<td>A10S</td>
				<td>400 RIDGE MALL</td>
				<td>SALS</td>
				<td>MO</td>
				<td>33906</td>
				<td>Active</td>
				<td>Y</td>
				<td/>
				<td>4670017054</td>
				<td>4670017005</td>
				<td>1199163600000</td>
				<td>1199509200000</td>
				<td>1201842000000</td>
				<td>781231</td>
				<td>94075R</td>

etc...
				
			</tr>
			<tr>
				<td>Electric Co</td>
				<td>0042</td>
				<td>A10S</td>
				<td>400 RIDGE</td>
				<td>SALS</td>
				<td>MO</td>
				<td>33906</td>
				<td>Active</td>
				<td>Y</td>
				<td/>
				<td>4670017054</td>
				<td>4670017005</td>
				<td>1201842000000</td>
				<td>1201928400000</td>
				<td>1204606800000</td>
etc...
				
			</tr>

Try with xsl:choose.

<xsl:template match="data">
<xsl:for-each select="tr">
<xsl:choose>
<xsl:when test="position()=1">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:when test="td[11] = preceding-sibling::tr/td[11] ">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:otherwise>
<a>It is not matching</a>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>

Regards,
Balaji. M

Thank you for your response Msbalaji. For some reason if I template match on "data" I'm having issues with the setup I have on this end. I have to go via the "columns" to get the index i.e.:

<xsl:variable name="acctnoIdx" select="number($colMap/col[@name='ACCTNO']/@idx)" />

then

<xsl:variable name="acctno" select="../tr/td[$acctnoIdx]" />

is returning ALL account numbers. I need to now figure out how to drill down to individual accnos.

Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.