Re: [xsl] How can I chang the value og a global variable?

Subject: Re: [xsl] How can I chang the value og a global variable?
From: Mike Brown <mike@xxxxxxxx>
Date: Fri, 15 Nov 2002 10:59:24 -0700 (MST)
Marcial Atienzar Navarro wrote:
> Hello everybody,
> 
>  I'm working with jstl. I've a jsp that has the structure of a xml. I need to
> make a table with paging. I obtain the values of the table with jsp tags, and
> mount the xml. To make the paging a need to know what is the last id of the table:
> 
>       <entrys>
>               <entry><s2k:GetData dataName="{$tabla}" columnNum="1" /></entry>
>               <entry><s2k:GetData dataName="{$tabla}" columnNum="2" /></entry>
>               <param><s2k:GetRowNumber tableName="{$tabla}"/></param>
>       </entrys>  
> 
>  Is to say, in the node param I have the value of this ID. In the xsl I need to
> take only the last index, because this is the correct.
> 
>  When I had the correct value of this variable I need to introduce a script code
> to finish.
> 
>  A lot of thanks,
> 
>    Marcial Atienzar

As David said, it is hard to understand your problem without seeing more code
(the input and desired output of the XSLT transformation). The fact that you
are mentioning JSP makes it more confusing; XSLT is only about node tree
transformation, with XML input and (generally speaking) XML-like output.

However, since you mention "table with paging", perhaps you just need to
follow this common design pattern, in which you use the help of position() and
the 'mod' operator (remainder after division) to select only the nodes that
start each "page", and then define the way to process of each of these nodes
to be: identify the current node and next (number of nodes on each page,
minus 1) nodes, and go process them.

For example, given XML source...

  <doc>
    <data xml:lang="en">hello world!</data>
    <data xml:lang="es">&#161;hola mundo!</data>
    <!-- ... -->
    <data xml:lang="se">hall&#229; v&#228;rld!</data>
  </doc>

And a desire to output a separate table of rows with up to $n rows ($n is a 
number) in each table, one row per 'data' element (we'll use $n=3 as an 
example):

  <table>
    <tr><td>en</td><td>hello world!</td></tr>
    <tr><td>es</td><td>&#161;hola mundo!</td></tr>
    <tr><td>...</td><td>...</td></tr>
  </table>
  <!-- ... more 3-row tables ... -->
  <table>
    <tr><td>...</td><td>...</td></tr>
    <tr><td>...</td><td>...</td></tr>
    <tr><td>se</td><td>hall&#229; v&#228;rld!</td></tr>
  </table>

Then your XSLT templates would look like this...

  <!-- default $n=3 -->
  <xsl:param name="n" select="3"/>

  <xsl:template match="doc">
    <!-- new table for every nth 'data' element -->
    <xsl:for-each select="data[position() mod $n = 1]">
      <table>
        <!-- new row for current 'data' and next $n-1 'data' -->
        <xsl:apply-templates select=".|follow-sibling::data[position() &lt; $n]"/>
      </table>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="data">
    <!-- generate the row for the current 'data' element -->
    <tr>
      <td><xsl:value-of select="@xml:lang"/></td>
      <td><xsl:value-of select="."/></td>
    </tr>
  </xsl:template>

Perhaps this is approximately what you are trying to do, and you can adapt 
this technique to your data?

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/

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


Current Thread