[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: to get form one xml file and other XSLT file (bell

Subject: Re: to get form one xml file and other XSLT file (bellow the code) one talee with 2 columns. SOS
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Wed, 5 Mar 2003 23:15:42 +0100
xslt form xml param
Hi Dionisio,

This transformation produces the wanted result:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html" />
  <xsl:strip-space elements="*"/>

   <xsl:template match="/">
     <table>
       <xsl:for-each
         select="/*/votacion[position() mod 2 = 1]">

         <tr>
           <xsl:apply-templates
              select=". | following-sibling::votacion[1]"/>
         </tr>

       </xsl:for-each>
     </table>
   </xsl:template>

   <xsl:template match="votacion">
     <td>
       <xsl:for-each select="registro/resultado">
         <xsl:value-of select="concat('res: ', .)"/>
         <xsl:if test="position() != last()"> - </xsl:if>
       </xsl:for-each>
     </td>
   </xsl:template>

</xsl:stylesheet>

When applied to this source.xml:

<registros>
  <votacion>
    <registro>
      <resultado>102</resultado>
    </registro>
    <registro>
      <resultado>22</resultado>
    </registro>
  </votacion>
  <votacion>
    <registro>
      <resultado>56</resultado>
    </registro>
    <registro>
      <resultado>31</resultado>
    </registro>
    <registro>
      <resultado>36</resultado>
    </registro>
  </votacion>
  <votacion>
    <registro>
      <resultado>02</resultado>
    </registro>
    <registro>
      <resultado>62</resultado>
    </registro>
  </votacion>
  <votacion>
    <registro>
      <resultado>66</resultado>
    </registro>
    <registro>
      <resultado>33</resultado>
    </registro>
    <registro>
      <resultado>36</resultado>
    </registro>
  </votacion>
  <votacion>
    <registro>
      <resultado>122</resultado>
    </registro>
    <registro>
      <resultado>24</resultado>
    </registro>
  </votacion>
</registros>

the result is:

<table>
<tr>
<td>res: 102 - res: 22</td>
<td>res: 56 - res: 31 - res: 36</td>
</tr>
<tr>
<td>res: 02 - res: 62</td>
<td>res: 66 - res: 33 - res: 36</td>
</tr>
<tr>
<td>res: 122 - res: 24</td>
</tr>
</table>

In case you need a table with nCols columns, you can modify the above
transformation like this:

  <xsl:param name="nCols" select="3"/>

   <xsl:template match="/">
     <table>
       <xsl:for-each
         select="/*/votacion[position() mod $nCols = 1]">

         <tr>
           <xsl:apply-templates
              select=". | following-sibling::votacion[position() &lt;
$nCols]"/>
         </tr>

       </xsl:for-each>
     </table>
   </xsl:template>


Hope this helped.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Dionisio Ruiz de Zarate" <dionisio@xxxxxxxxxxxxx> wrote in message
news:002b01c2e34f$2a6f1640$0201a8c0@xxxxxxx
> Witn the bellow XML and XSLT fiel i want to get this:
> <table>
> <tr><td>res: 102 - res: 22</td><td>res: 56 - res: 31 - res: 36</td></tr>
> <!-- more elements here -->
> </table>
>
> i want to get one table with 2 columns and x rows. but i dont get it
> o dont presents the two columns
> can you help me please? i am two weeks with this problem and i dont solve
> it.
> plase can you help me?
> thanks
>
> XML file:
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <registros>
> <votacion>
>         <registro>
>                 <resultado>102</resultado>
>         </registro>
>         <registro>
>                 <resultado>22</resultado>
>         </registro>
> </votacion>
> <votacion>
>         <registro>
>                 <resultado>56</resultado>
>         </registro>
>         <registro>
>                 <resultado>31</resultado>
>         </registro>
>         <registro>
>                 <resultado>36</resultado>
>         </registro>
> </votacion>
> </registros>
>
>
> XSLT template:
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xhtml" version="1.0" encoding="ISO-8859-1"
> indent="yes"/>
> <xsl:template match="/">
> <table>
> <xsl:for-each select="/registros/votacion">
>   <xsl:if test="position() mod 2 = 1 or position()=1">
>     <xsl:call-template name="Make2ColumnRow">
>       <xsl:with-param name="FirstItemPositionNo">
>         <xsl:value-of select="position()"/>
>       </xsl:with-param>
>     </xsl:call-template>
>   </xsl:if>
> </xsl:for-each>
> </table>
> </xsl:template>
> <xsl:template name="Make2ColumnRow">
> <xsl:param name="FirstItemPositionNo"/>
> <tr>
> <td>
>   <xsl:for-each select="/registros/votacion/registro">
>       res: <xsl:variable name="myVarGrafica"
> select="self::node()[position()=$FirstItemPositionNo]/resultado" />res:
> </xsl:for-each>
> </td>
> <td>
> <xsl:for-each select="/registros/votacion/registro">
>       res: <xsl:variable name="myVarGrafica"
> select="self::node()[position()=$FirstItemPositionNo+1]/resultado" />
> </xsl:for-each>
> </td>
> </tr>
> </xsl:template>
> </xsl:stylesheet>
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>




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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.