[xsl] Problem with position( ) function

Subject: [xsl] Problem with position( ) function
From: "Jaime A Stuardo Bahamondes" <jstuardo@xxxxxxxxxxx>
Date: Thu, 27 Nov 2003 17:41:20 -0400
Hi all..

I have this piece of XML:

<actividades>
  <ROWSET>
    <ROW id="1">
      <ACT_ID>6</ACT_ID>
      <ACT_FEC_ING>27-11-2003 09:43:32</ACT_FEC_ING>
      <ACT_DES_LAR>Finanzas, Impuestos y Política Monetaria</ACT_DES_LAR>
      <ACT_DES_COR>Finanzas, Impuestos y Política Monetaria</ACT_DES_COR>
      <ACT_EST>v</ACT_EST>
      <ACT_AGR_ID>1</ACT_AGR_ID>
    </ROW>
    <ROW id="2">
      <ACT_ID>1</ACT_ID>
      <ACT_FEC_ING>27-11-2003 09:43:31</ACT_FEC_ING>
      <ACT_DES_LAR>Gobierno en General, Municipalidades</ACT_DES_LAR>
      <ACT_DES_COR>Gobierno en General, Municipalidades</ACT_DES_COR>
      <ACT_EST>v</ACT_EST>
      <ACT_AGR_ID>1</ACT_AGR_ID>
    </ROW>
    -......---
</actividades>
<agrupaciones>
  <ROWSET>
    <ROW id="1">
      <AGR_ID>1</AGR_ID>
      <AGR_FEC_ING>11-11-2003</AGR_FEC_ING>
      <AGR_FEC_MOD>14-11-2003 11:22:04</AGR_FEC_MOD>
      <AGR_DES_LAR>Administración Publica</AGR_DES_LAR>
      <AGR_DES_COR>Administración Publica</AGR_DES_COR>
      <AGR_EST>v</AGR_EST>
    </ROW>
    <ROW id="2">
      <AGR_ID>2</AGR_ID>
      <AGR_FEC_ING>18-11-2003 11:34:08</AGR_FEC_ING>
      <AGR_DES_LAR>Agricultura</AGR_DES_LAR>
      <AGR_DES_COR>Agricultura</AGR_DES_COR>
      <AGR_EST>v</AGR_EST>
    </ROW>
</agrupaciones>


I'm programming an XSL that generates a JavaScript this way:

var actividades = new Array(2);	// 2 "agrupaciones"
actividades[0] = new Array(6, 1);	// 6 and 1 are "actividades" corresponding to "agr_id" = 1
actividades[1] = new Array(7,9,15);	// 7, 9 and 15 are "actividades" corresponding to "agr_id" = 2 (not shown in XML above)
and so on.

I programmed this XSL:

<xsl:template match="agrupaciones/ROWSET/ROW">
  actividades[<xsl:value-of select="position()-1"/>] = new Array(<xsl:apply-templates select="../../../actividades/ROWSET/ROW"><xsl:with-param name="agr_id"><xsl:value-of select="AGR_ID" /></xsl:with-param></xsl:apply-templates>)
</xsl:template>
        
<xsl:template match="actividades/ROWSET/ROW">
  <xsl:param name="agr_id" />
  <xsl:if test="ACT_AGR_ID = $agr_id">'<xsl:value-of select="position()" />|<xsl:value-of select="ACT_DES_COR" />'<xsl:if test = "position() &lt; last() ">,</xsl:if></xsl:if>

</xsl:template>

The problem I have is that the following is generated by those templates:

actividades[0] = new Array(6,1,);		// realize about the last "comma"
actividades[1] = new Array(7,9,15,);

To avoid that, I placed the condition position() &lt; last(), but I realized that position( ) isn't resetted by each iteration of the template. Any help on this?

And other question. I have placed all the xsl instructions on the same line because if I write the xsl more readable, empty lines are inserted in the generated JavaScript. Is it possible to solve it?

Thanks in advance
Jaime

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread