xsl-list
[Top] [All Lists]

Re: Problem with position( ) function

2003-11-27 20:29:29
I am not sure what you are trying to do as your JavaScript and what you 
are showing the xslt to generate seems different but I assume you want to 
haver these ACT_DES_COR data there but then your foramt seems very 
complicated. 

Anyway this is not the issue and maybe you don't want/can't change it but 
still I think you over-complicated the matter a lot. Unless you are trying 
to do as well with the template <xsl:template 
match="actividades/ROWSET/ROW">  then I think that (assuming that this is 
waht you want to do)  you just have to call a template when you want to 
construct the array:

Array(<xsl:call-templates select="actividades-indexing"><xsl:with-param 
name="agr_id" select="AGR_ID" /></xsl:call-template>)


<xsl:template name="actividades-indexing">
  <xsl:param name="agr_id" />
  <xsl:for-each select="/yourroot/actividates/ROWSET/ROW[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:fot-each>
</xsl:template>

I am sorry I cannot test it at the moment but it seems consistent with 
what you want to do. 

Manolis

p.s. btw I don't know what you want to do with these data assigned in 
the Arrays but in a similiar case I used JavaScript 'hashmaps' to assign things 
into and then when I needed to call them i just refered to them with 
their id


On Thu, 27 Nov 2003, Jaime A Stuardo Bahamondes wrote:

       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
       
       


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



<Prev in Thread] Current Thread [Next in Thread>