473,805 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xml/xslt help

Bob
I am having problems turning my xml into html for display. A sample
xml file is given below, followed by my pathetic xslt attempt to
transform it into html. A textual representation of what I was hoping
to see is last. I am using saxon to do the transformation.

<?xml version="1.0"?>
<Whatever>
<Company>Compan y One
<DateRange>21-27Mar2004</DateRange>
<SubOrg>Divisio n A
<Data>163
<Description> A description of 163, Div A, Comp A</Description>
</Data>
<Data>201
<Description>De scription of 201, Div. A, Comp A</Description>
</Data>
</SubOrg>
<SubOrg>Divisio n B
<Data>213
<Description>Mo re descriptive text.</Description>
</Data>
<Data>222
<Description>Ag ain, more stuff.</Description>
</Data>
</SubOrg>
</Company>
</Whatever>
<?xml version="1.0"?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>
<head><title>Ti tle Information</title></head>
<body bgcolor="white" >
<p align="center"> <font size="+3">Repor t</font></p>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="Company" >
<br/>
<p><font size="+2" color="green">< xsl:value-of
select="."/></font></p>
<xsl:apply-templates select="DateRan ge"/>
<xsl:apply-templates select="SubOrg"/>
<xsl:apply-templates select="Data"/>
</xsl:template>
<xsl:template match="DateRang e">
<p><font color="blue"><x sl:value-of select="."/></font></p>
</xsl:template>
<xsl:template match="SubOrg">
<br/><font size="+1" color="red"><xs l:value-of
select="."/></font>
</xsl:template>
<xsl:template match="Data">
<br/><font color="black">< xsl:value-of select="."/></font>
</xsl:template>
</xsl:stylesheet>
What I would like to see is some html that would appear somewhat like
this:
Report
Company One
21-27Mar2004
Division A
163 - A description of 163, Div A, Comp A
201 - Description of 201, Div. A, Comp A
Division B
213 -
222 -
Company Two
07-14Apr2004
Division A
128 -
Division B
221 -
234 -

etc...

I am using saxon to turn the xml/xslt into html. It's probably
obvious that I'm not getting the html I wanted.

Can any provide some help? Thanks in advance!

Bob.
Jul 20 '05 #1
2 1745
gr**********@ya hoo.com (Bob) writes:
I am having problems turning my xml into html for display. A sample
xml file is given below, followed by my pathetic xslt attempt to
transform it into html. A textual representation of what I was hoping
to see is last. I am using saxon to do the transformation.

<?xml version="1.0"?>
<Whatever>
<Company>Compan y One
<DateRange>21-27Mar2004</DateRange>
<SubOrg>Divisio n A
<Data>163
<Description> A description of 163, Div A, Comp A</Description>
</Data>
<Data>201
<Description>De scription of 201, Div. A, Comp A</Description>
</Data>
</SubOrg>
<SubOrg>Divisio n B
<Data>213
<Description>Mo re descriptive text.</Description>
</Data>
<Data>222
<Description>Ag ain, more stuff.</Description>
</Data>
</SubOrg>
</Company>
</Whatever>


You've got the right idea, but a couple of comments:

- the difficulty with your XML is that not every item is wrapped up
individually as an element. So in

<Data>163
<Description> A description of 163, Div A, Comp A</Description>
</Data>

the Data element contains two nodes: a text node and a Description
node. Your <xsl:value-of select="."/> extracts the text of both.
Extracting just the text node is ugly: you can use text(), but you
get all the newlines and junk, so I used normalize-space(text()).

It would be much neater and flexible if you could rewrite this as

<Data>
<Title>163</Title>
<Description> A description of 163, Div A, Comp A</Description>
</Data>

for example.

- You should read up on CSS. <p align="center"> <font size="+3">
Report</font></p> is truly horrible. The modern way is to mark it
up as <h1> or whatever and use CSS to style it.
This transformation with your data

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

<xsl:template match="/">
<html>
<head><title>Ti tle Information</title></head>
<body>
<h1>Report</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="Company" >
<h2><xsl:valu e-of select="normali ze-space(text())"/></h2>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="DateRang e">
<h3><xsl:valu e-of select="normali ze-space(text())"/></h3>
</xsl:template>

<xsl:template match="SubOrg">
<h4><xsl:valu e-of select="normali ze-space(text())"/></h4>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="Data">
<p>
<xsl:value-of select="normali ze-space(text())"/>
<xsl:text> - </xsl:text>
<xsl:value-of select="Descrip tion"/>
</p>
</xsl:template>

<!-- Omit text not explicitly dealt with above -->
<xsl:template match="text()"/>

</xsl:stylesheet>
gives
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Title Information</title>
</head>
<body>
<h1>Report</h1>
<h2>Company One</h2>
<h3>21-27Mar2004</h3>
<h4>Division A</h4>
<p>163 - A description of 163, Div A, Comp A</p>
<p>201 - Description of 201, Div. A, Comp A</p>
<h4>Division B</h4>
<p>213 - More descriptive text.</p>
<p>222 - Again, more stuff.</p>
</body>
</html>
Which is approximately what you want.

--
Ben Edgington
Mail to the address above is discarded.
Mail to ben at that address might be read.
http://www.edginet.org/
Jul 20 '05 #2
Bob
Ben,

Thanks for the help - it is greatly appreciated. I'm going to give it
a try this morning.

Bob.
Jul 20 '05 #3

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

Similar topics

6
2750
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a straight XML file http://www.discovertravelandtours.com/test/templates/test.xml?Location=Germany To another XML file http://www.discovertravelandtours.com/test/templates/test2.xml?Location=Germany
1
8692
by: Victor | last post by:
Hi, this might sound silly but I cannot figure out how to incorporate some XML of employees into some XML of a company to give new XML containing them all. For example, this is the company now <COMPANY> <EMPLOYEE currentEmployee="true"> <NAME>Victor</NAME>
12
3240
by: gipsy boy | last post by:
Hello, I have sort of a big problem. I would really appreciate any help you could give me. I made a web service in C++ that throws XML to the client (browser). But, the XSLT transormation (xml->html) doen't happen! I have XSLT files for this, they work, I mean when I put the output of the app as an XML file on some server, and make it use the XSLT files to transform into HTML, it works, I get a HTML page.
5
7644
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 business components that can be consumed by WebForms, WinForms, mobile devices, etc? Is it even fair to compare the such technologies? - How about for cases when you need to display dynamic elements on the form/grid (as compared to knowing data elements...
4
1833
by: Chris Kettenbach | last post by:
Hi Peter, I get error when processing the stylesheet. It errors here. <xsl:for-each select="registration)=1]"> specifically: Expression does not return a DOM node. registration)=1]<--
4
2174
by: Moogy | last post by:
I'm pulling my hair out here. First, I'm new to XML, so that doesn't help, but none of this makes any sense to me. All I'm trying to do is take a simple source XML file and translate it with an XSLT to produce HTML code. The problem I have is that no matter what translation it runs through, it ALWAYS includes data that I don't match in the XSLT!! All I want to do is extract specific fields from the XML. Here's the XML source....
7
2872
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID); xmlItems.TransformArgumentList = xsltArgList;
3
2012
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as processor input. The basic class hierarchy is:
18
2090
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to look up what each feature depends on and gerenate a text file. For example, in the following file, I would like to find out feature A depends on A1 and A2 and feature B depends on B1 and B2. And write that to a text file.
15
2164
by: Jeff Uchtman | last post by:
Can I draw from 2 XML sources, the structure is exactly the same execpt for data contained into 1 xslt using math to add some structrure, and displaying others as node 1 and node 2? This data is XML from a Barracuda Spam server that has grown to 2. Here is a snip from my form draw. Imports System Imports System.IO Imports System.Net
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10604
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10356
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10361
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10103
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6874
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.