modulo

Discussion in 'XML' started by graf.laszlo@axis.hu, Jul 24, 2006.

  1. Guest

    Hi all,

    I have an XML structure wich looks like this:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <a>
    <b1 id="1">
    <c1>C11</c1>
    <c2>C12</c2>
    ...
    </b1>
    <b1 id="2">
    <c1>C21</c1>
    <c2>C22</c2>
    ...
    </b1>
    <b1 id="3">
    <c1>C31</c1>
    <c2>C32</c2>
    ...
    </b1>
    ...
    <b1 id="m">
    <c1>C(m)1</c1>
    <c2>C(m)2</c2>
    ...
    </b1>
    </a>
    where the number of 'b' tags is greater than 3 and the number of 'c'
    tags is greater than 2.
    How can I transform the XML data using XSLT to get the following HTML
    table structure?

    <table>
    <tr>
    <td>
    <table>
    <tr>
    <th>b1 (id=1)</th>
    <td>c1 : C11</td>
    <td>c2 : C12</td>
    ...
    </tr>
    </table>
    </td>
    <td>
    <table>
    <tr>
    <th>b1 (id=2)</th>
    <td>c1 : C21</td>
    <td>c2 : C22</td>
    ...
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td>
    <table>
    <tr>
    <th>b1 (id=3)</th>
    <td>c1 : C31</td>
    <td>c2 : C32</td>
    ...
    </tr>
    </table>
    </td>
    <td>
    <table>
    <tr>
    <th>b1 (id=4)</th>
    <td>c1 : C41</td>
    <td>c2 : C42</td>
    ...
    </tr>
    </table>
    </td>
    </tr>
    ...
    </table>

    Thank you,
    Laci
    , Jul 24, 2006
    #1
    1. Advertising

  2. George Bina Guest

    Hi Laci,

    I cannot see any difficulty here, something as simple as the stylesheet
    below will get you the desired output:

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

    <xsl:template match="a">
    <table>
    <tr><xsl:apply-templates/></tr>
    </table>
    </xsl:template>
    <xsl:template match="b1">
    <td>
    <table>
    <tr>
    <th><xsl:value-of select="name()"/> (id=<xsl:value-of
    select="@id"/>)</th>
    <xsl:apply-templates/>
    </tr>
    </table>
    </td>
    </xsl:template>
    <xsl:template match="c1|c2">
    <td><xsl:value-of select="name()"/> : <xsl:value-of
    select="."/></td>
    </xsl:template>
    </xsl:stylesheet>

    Best Regards,
    George
    ---------------------------------------------------------------------
    George Cristian Bina
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com

    wrote:
    > Hi all,
    >
    > I have an XML structure wich looks like this:
    >
    > <?xml version="1.0" encoding="ISO-8859-1"?>
    > <a>
    > <b1 id="1">
    > <c1>C11</c1>
    > <c2>C12</c2>
    > ...
    > </b1>
    > <b1 id="2">
    > <c1>C21</c1>
    > <c2>C22</c2>
    > ...
    > </b1>
    > <b1 id="3">
    > <c1>C31</c1>
    > <c2>C32</c2>
    > ...
    > </b1>
    > ...
    > <b1 id="m">
    > <c1>C(m)1</c1>
    > <c2>C(m)2</c2>
    > ...
    > </b1>
    > </a>
    > where the number of 'b' tags is greater than 3 and the number of 'c'
    > tags is greater than 2.
    > How can I transform the XML data using XSLT to get the following HTML
    > table structure?
    >
    > <table>
    > <tr>
    > <td>
    > <table>
    > <tr>
    > <th>b1 (id=1)</th>
    > <td>c1 : C11</td>
    > <td>c2 : C12</td>
    > ...
    > </tr>
    > </table>
    > </td>
    > <td>
    > <table>
    > <tr>
    > <th>b1 (id=2)</th>
    > <td>c1 : C21</td>
    > <td>c2 : C22</td>
    > ...
    > </tr>
    > </table>
    > </td>
    > </tr>
    > <tr>
    > <td>
    > <table>
    > <tr>
    > <th>b1 (id=3)</th>
    > <td>c1 : C31</td>
    > <td>c2 : C32</td>
    > ...
    > </tr>
    > </table>
    > </td>
    > <td>
    > <table>
    > <tr>
    > <th>b1 (id=4)</th>
    > <td>c1 : C41</td>
    > <td>c2 : C42</td>
    > ...
    > </tr>
    > </table>
    > </td>
    > </tr>
    > ...
    > </table>
    >
    > Thank you,
    > Laci
    George Bina, Jul 24, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian Kruggel

    General modulo-question

    Christian Kruggel, Jul 7, 2003, in forum: Java
    Replies:
    1
    Views:
    439
    Brad BARCLAY
    Jul 7, 2003
  2. Replies:
    1
    Views:
    654
    Darryl L. Pierce
    May 20, 2004
  3. Tjerk Wolterink

    [xsl] sort & modulo

    Tjerk Wolterink, Apr 21, 2005, in forum: XML
    Replies:
    3
    Views:
    557
    Dimitre Novatchev
    Apr 22, 2005
  4. silentlights

    Fast Division/Modulo Operation

    silentlights, Apr 16, 2004, in forum: C Programming
    Replies:
    8
    Views:
    972
    Dik T. Winter
    Apr 23, 2004
  5. Griff

    Problems using modulo

    Griff, Apr 19, 2004, in forum: Python
    Replies:
    5
    Views:
    387
    Diez B. Roggisch
    Apr 20, 2004
Loading...

Share This Page