473,396 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to do XSLT for this?

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

Jul 20 '05 #1
3 1895
mali djuro wrote:
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.
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.

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() = ''"> </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
Kl********@atmedia.net
http://www.atmedia.net/KlausRusch/
Jul 20 '05 #2
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>

"mali djuro" <ma***************@net.hr> wrote in message
news:be***********@as201.hinet.hr...
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

Jul 20 '05 #3
thanks,

it was typing mistake with name and child
"Colin Mackenzie" <co***@elecmc.com> wrote in message
news:be**********@newsg1.svr.pol.co.uk...
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>

"mali djuro" <ma***************@net.hr> wrote in message
news:be***********@as201.hinet.hr...
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


Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ted | last post by:
Was wondering if XSLT alone is appropriate for the following situation. From XML, I'm creating a small website (around 50 pages) with pages that link to each other through a nav menu and a...
2
by: Tom Corcoran | last post by:
I am working to ease updating of a html page by transforming 2 xml files. I was going to use xslt for this and had bought 2 unopened books, wrox xslt and o'reilly's xslt cookbook. But am now...
1
by: Mohit | last post by:
Hi Friends I have to call 1 of the 2 child XSLT files from the Main XSLT file based on some criteria. I want one child XSLT file will be executed by version 1 of XSLT processor and the other by...
5
by: Fred | last post by:
Not much expertise on XSLT and trying to understand it's uses when creating apps in VS.NET? If I wanted flexibility on the UI (View aspect of M.V.C.): - How does it compare with creating...
4
by: Stephen | last post by:
I have the following that outputs an xml file to a div using ajax: <script type="text/javascript"> function ajaxXML(url,control_id){ if (document.getElementById) { var x =...
5
by: shauldar | last post by:
Is there a way (tool, hack...) to create an XSL:FO from an XSLT + XML files? My motivation is that we want to use a tool to design reports, and from that "design" generate both HTML (via XSLT)...
10
by: daz_oldham | last post by:
Hi I am doing an XSLT that processes (for example) a list of hotels. Each hotel has the attribute @StarRating which is one of the following values: * ** *** ****
1
by: Nick | last post by:
I am working on a website for a client and one of their requirements was to have a mailing list. I decided to XSLT to transform "templates" to HTML so that editing was very easy and less time...
1
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT...
3
by: RC | last post by:
Let's say: if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { // Now I got an XML object here var xmlDocument = XMLHttpRequestObject.responseXML; // next I have...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.