How to do XSLT for this?

How to do XSLT for this?

Post by mali djur » Fri, 04 Jul 2003 16:39:56



Hi, all!

i am newbie in all this stuffs about xsl, so i have few questions for you,
Please, can you tell me is this possible to do, and if you can please give
me some guide lines.

here is problem or whatever:

i got a following xml file:

<root>
    <sub>
        <child>
            <name>john</child>
            <phone>1234</phone>
        </child>
        <child>
            <name>mali</name>
            <phone />
        </child>
        ...
    </sub>
</root>

i want to show this xml in browser in following way:

----------------------------------------------
|                      TEST                                     |
----------------------------------------------
| child name             |     child phone               |
----------------------------------------------
| john                      |           1234                   |
bgColor=blue
----------------------------------------------
|mali                        |                                      |
bgcolor=white
----------------------------------------------
...
----------------------------------------------

problem is that i dont know how to change background colour of <tr>.
and also how to check is value of element null or there is something?

please, help!

thanks

 
 
 

How to do XSLT for this?

Post by Klaus Johannes Rusc » Fri, 04 Jul 2003 17:37:52



> i am newbie in all this stuffs about xsl, so i have few questions for you,
> Please, can you tell me is this possible to do, and if you can please give
> me some guide lines.

> here is problem or whatever:

> i want to show this xml in browser in following way:

Define templates for each element that output the desired HTML code, and apply
templates for contained elements. The samples in the XSLT specification, or a
decent XSLT book such as Michael Kay's or Doug Tidwell's certainly will help,
too.

Quote:> problem is that i dont know how to change background colour of <tr>.

Not exactly an XSLT problem but here you go:

<tr>
<td bgcolor="red">
</td>
<td bgcolor="red">
</td>
</tr>

You can check if the position of your element is even or odd, and use
different colors accordingly.

Quote:

> and also how to check is value of element null or there is something?

Even for an element without content you will still want to include the <td>,
you could do something like

<td>
<xsl:choose>
  <xsl:when test="phone/text() = ''">&#160;</xsl:when>
  <xsl:otherwise><xsl:value-of select="phone/text()" />
</xsl:choose>
</td>

if you want to include a non-breaking space (or some other information, like
N/A) for empty cells.

--
Klaus Johannes Rusch

http://www.atmedia.net/KlausRusch/

 
 
 

How to do XSLT for this?

Post by Colin Mackenzi » Fri, 04 Jul 2003 17:37:25


Hi,

your xml is not well formed (name should be closed with name not child)

colout or a tr, I guess you are saying for every 2nd row bit of an FAQ but
this will work

<xsl:template match="/root/sub">
    <table>
        <tbody>
            <xsl:for-each select="child">
   <xsl:choose>
    <xsl:when test="(position()=1) or (position() mod 2 = 1) ">
     <tr bgcolor="blue">
      <td><xsl:value-of select="name"/></td>
      <td>
       <xsl:choose>
        <xsl:when test="phone=''">no phone</xsl:when>
        <xsl:otherwise><xsl:value-of select="phone"/></xsl:otherwise>
       </xsl:choose>
      </td>
     </tr>
    </xsl:when>
    <xsl:otherwise>
     <tr bgcolor="white">
      <td><xsl:value-of select="name"/></td>

      <td>
       <xsl:choose>
        <xsl:when test="phone=''">no phone</xsl:when>
        <xsl:otherwise><xsl:value-of select="phone"/></xsl:otherwise>
       </xsl:choose>
      </td>
     </tr>
    </xsl:otherwise>
   </xsl:choose>
            </xsl:for-each>
        </tbody>
    </table>
</xsl:template>


Quote:> Hi, all!

> i am newbie in all this stuffs about xsl, so i have few questions for you,
> Please, can you tell me is this possible to do, and if you can please give
> me some guide lines.

> here is problem or whatever:

> i got a following xml file:

> <root>
>     <sub>
>         <child>
>             <name>john</child>
>             <phone>1234</phone>
>         </child>
>         <child>
>             <name>mali</name>
>             <phone />
>         </child>
>         ...
>     </sub>
> </root>

> i want to show this xml in browser in following way:

> ----------------------------------------------
> |                      TEST                                     |
> ----------------------------------------------
> | child name             |     child phone               |
> ----------------------------------------------
> | john                      |           1234                   |
> bgColor=blue
> ----------------------------------------------
> |mali                        |                                      |
> bgcolor=white
> ----------------------------------------------
> ...
> ----------------------------------------------

> problem is that i dont know how to change background colour of <tr>.
> and also how to check is value of element null or there is something?

> please, help!

> thanks

 
 
 

How to do XSLT for this?

Post by mali djur » Fri, 04 Jul 2003 18:01:47


thanks,

it was typing mistake with name and child


> Hi,

> your xml is not well formed (name should be closed with name not child)

> colout or a tr, I guess you are saying for every 2nd row bit of an FAQ but
> this will work

> <xsl:template match="/root/sub">
>     <table>
>         <tbody>
>             <xsl:for-each select="child">
>    <xsl:choose>
>     <xsl:when test="(position()=1) or (position() mod 2 = 1) ">
>      <tr bgcolor="blue">
>       <td><xsl:value-of select="name"/></td>
>       <td>
>        <xsl:choose>
>         <xsl:when test="phone=''">no phone</xsl:when>
>         <xsl:otherwise><xsl:value-of select="phone"/></xsl:otherwise>
>        </xsl:choose>
>       </td>
>      </tr>
>     </xsl:when>
>     <xsl:otherwise>
>      <tr bgcolor="white">
>       <td><xsl:value-of select="name"/></td>

>       <td>
>        <xsl:choose>
>         <xsl:when test="phone=''">no phone</xsl:when>
>         <xsl:otherwise><xsl:value-of select="phone"/></xsl:otherwise>
>        </xsl:choose>
>       </td>
>      </tr>
>     </xsl:otherwise>
>    </xsl:choose>
>             </xsl:for-each>
>         </tbody>
>     </table>
> </xsl:template>



> > Hi, all!

> > i am newbie in all this stuffs about xsl, so i have few questions for
you,
> > Please, can you tell me is this possible to do, and if you can please
give
> > me some guide lines.

> > here is problem or whatever:

> > i got a following xml file:

> > <root>
> >     <sub>
> >         <child>
> >             <name>john</child>
> >             <phone>1234</phone>
> >         </child>
> >         <child>
> >             <name>mali</name>
> >             <phone />
> >         </child>
> >         ...
> >     </sub>
> > </root>

> > i want to show this xml in browser in following way:

> > ----------------------------------------------
> > |                      TEST                                     |
> > ----------------------------------------------
> > | child name             |     child phone               |
> > ----------------------------------------------
> > | john                      |           1234                   |
> > bgColor=blue
> > ----------------------------------------------
> > |mali                        |                                      |
> > bgcolor=white
> > ----------------------------------------------
> > ...
> > ----------------------------------------------

> > problem is that i dont know how to change background colour of <tr>.
> > and also how to check is value of element null or there is something?

> > please, help!

> > thanks

 
 
 

How to do XSLT for this?

Post by Christophe Jacque » Fri, 04 Jul 2003 18:31:29


Hi,

Quote:>      <tr bgcolor="blue">

The "bgcolor" attribute is deprecated
(http://www.w3.org/TR/html4/present/graphics.html#adef-bgcolor).

You should use Cascading Stylesheets (http://www.w3.org/Style/CSS/) instead:

In XHTML:
        <tr class="oddline">...</tr>
        <tr class="evenline">...</tr>
        ...

And in CSS:
        tr.oddline { background-color: blue; }
        tr.evenline { background-color: white; }

Note that in CSS level 3, using selectors, you won't even have to change
the markup to alternate the background color of rows in a table (see
http://www.xml.com/lpt/a/2003/06/18/css3-selectors.html).

--
Christophe Jacquet
http://jacquetc.free.fr/

 
 
 

1. HTTP "proxy" doing XSLT ?

i would like to programm the dynamic part of web apps in my favored
language (whatever this is), make it write XML an PI as output,
and have a proxy server that does the xslt to the nifty web page.

so i need some sort of a proxy server: pass the request to the
real dynamic webserver, take the output, transform it (processa
instructions are included in the request or could be pre-configured,
doesn't matter), and send it to the client.

sure, one integrated thing with <whatever i want> and XSLT would be
nice, but i get the fealing i can only have either. a proxy could be
a (possible slow ?) way to combine two nice things.

is there such a proxy ? anyone did this already ?
or something similiar ?

regards, andreas

2. Help on enable password for CISCO LS-1010 ATM Switch

3. Any way of doing XSLT JScript Functions ?

4. MSC by research?

5. (Yet Another) XML/XSL talk, done using XSLT

6. New Young programmer NEED HELP

7. How to prevent XSLT from doing URL encoding in <a href="#@firstchar">

8. user@hostname on outgoing mail

9. Hey guys, What is the most complex or difficult thing you ever done with XML/XSLT???

10. xslt output dos-encoding for batch files

11. Using XSLT to write DOS Batch Files

12. Anyone here doing research on XML index structure?

13. What am I doing wrong with xsl:template match="id ???