473,471 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problems with XML transformation with XSLT

2 New Member
Hi,

I am new to XSLT. Having problems creating an HTML table (specifically the headers) from an XML file like the following:

<group>
<categorylist>
<category>car</category>
<description>bently</description>
</categorylist>

<categorylist>
<category>car</category>
<description>bmw</description>
</categorylist>

<categorylist>
<category>computer</category>
<description>dell</description>
</categorylist>
</group>

So, I need to create a table where the first header (TH) should be 'car' with 2 TRs for 'bently' and 'bmw'. The next header should be 'computer' with only one TR for 'dell'. So, for each categorylist, I need to create a header for all categories with the same value and TRs for their corresponding 'description'.

Any help would be greatly appreciated.

Thanks.
Mar 14 '08 #1
4 1488
saran3b2
19 New Member
hi declare the variable for category and description
like this

<xsl:key name="keyCategory" match="categorylist" use="category"/>
<xsl:key name="keyDescription" match="categorylist" use="description"/>


and apply ur xslt coding like these


<xsl:for-each select="$group">
<xsl:variable name="category" select="category"/>
<xsl:variable name="description" select="description"/>
<xsl:if test="generate-id(.)=generate-id($group[category=$category])">
<tr>
<th><xsl:value-of select="category"/></th>
</tr>
<tr>
<td><xsl:value-of select="description"/></td>
</tr>

</xsl:if>

</xsl:for-each>


ok
-------------------------------------------------------------------------------------------------------


Hi,

I am new to XSLT. Having problems creating an HTML table (specifically the headers) from an XML file like the following:

<group>
<categorylist>
<category>car</category>
<description>bently</description>
</categorylist>

<categorylist>
<category>car</category>
<description>bmw</description>
</categorylist>

<categorylist>
<category>computer</category>
<description>dell</description>
</categorylist>
</group>

So, I need to create a table where the first header (TH) should be 'car' with 2 TRs for 'bently' and 'bmw'. The next header should be 'computer' with only one TR for 'dell'. So, for each categorylist, I need to create a header for all categories with the same value and TRs for their corresponding 'description'.

Any help would be greatly appreciated.

Thanks.
Mar 14 '08 #2
scripts08
2 New Member
Thank you very much for your response. For some reason, its not working for me. I am not sure why. Any idea? I checked several times to make sure I don't have any typo or anything but still no luck.



hi declare the variable for category and description
like this

<xsl:key name="keyCategory" match="categorylist" use="category"/>
<xsl:key name="keyDescription" match="categorylist" use="description"/>


and apply ur xslt coding like these


<xsl:for-each select="$group">
<xsl:variable name="category" select="category"/>
<xsl:variable name="description" select="description"/>
<xsl:if test="generate-id(.)=generate-id($group[category=$category])">
<tr>
<th><xsl:value-of select="category"/></th>
</tr>
<tr>
<td><xsl:value-of select="description"/></td>
</tr>

</xsl:if>

</xsl:for-each>


ok
-------------------------------------------------------------------------------------------------------
Mar 14 '08 #3
saran3b2
19 New Member
hi,

here ouput is the clear. Please verify in ur xml and xsl coding.


<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="group.xsl"?>
<group>
<categorylist>
<category>car</category>
<description>bently</description>
</categorylist>

<categorylist>
<category>car</category>
<description>bmw</description>
</categorylist>

<categorylist>
<category>computer</category>
<description>dell</description>
</categorylist>
</group>

Simply copy and paste this coding for out put
------------------------------------------------------

group.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="ISO-8859-1" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/>
<xsl:variable name="group" select="//categorylist"/>
<!-- Define keys used to group elements -->
<xsl:key name="keyCategory" match="categorylist" use="category"/>
<xsl:key name="keyDescription" match="categorylist" use="description"/>
<xsl:template match="/">
<html>
<head>
<title>Cengage Production Report</title>
</head>
<body>
<center>**************************************** </center>
<center>
<font size="6" color="brown">PreMedia Global P. Ltd.</font>
</center>
<center>**************************************** </center>
<center>
<font size="4" color="blue">Cengage Production Report</font>
</center>
<br/>
<table width="100%" frame="box" border="2" align="center">
<tbody>
<xsl:apply-templates/>
</tbody>
</table>
</body>
</html>
</xsl:template>



<xsl:template match="group" name="ShowproductionsInTeam">

<xsl:for-each select="$group">
<xsl:variable name="category" select="category"/>
<xsl:variable name="description" select="description"/>
<xsl:if test="generate-id(.)=generate-id($group[category=$category])">
<tr>
<th><xsl:value-of select="category"/></th>
</tr>
</xsl:if>
<tr>
<td><xsl:value-of select="description"/></td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Reply me if ouput clear

Regards
vinoth K



Thank you very much for your response. For some reason, its not working for me. I am not sure why. Any idea? I checked several times to make sure I don't have any typo or anything but still no luck.
Mar 17 '08 #4
saran3b2
19 New Member
hi,

Please ignore the previous mail.

here is ur xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="group.xsl"?>
<group>
<categorylist>
<category>car</category>
<description>bently</description>
</categorylist>

<categorylist>
<category>car</category>
<description>bmw</description>
</categorylist>

<categorylist>
<category>computer</category>
<description>dell</description>
</categorylist>
</group>


Simply copy and paste this coding for out put
------------------------------------------------------

group.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="ISO-8859-1" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/>
<xsl:variable name="group" select="//categorylist"/>
<!-- Define keys used to group elements -->
<xsl:key name="keyCategory" match="categorylist" use="category"/>
<xsl:key name="keyDescription" match="categorylist" use="description"/>
<xsl:template match="/">
<html>
<head>
<title>Report</title>
</head>
<body>
<table width="100%" frame="box" border="2" align="center">
<tbody>
<xsl:apply-templates/>
</tbody>
</table>
</body>
</html>
</xsl:template>



<xsl:template match="group" name="ShowproductionsInTeam">

<xsl:for-each select="$group">
<xsl:variable name="category" select="category"/>
<xsl:variable name="description" select="description"/>
<xsl:if test="generate-id(.)=generate-id($group[category=$category])">
<tr>
<th><xsl:value-of select="category"/></th>
</tr>
</xsl:if>
<tr>
<td><xsl:value-of select="description"/></td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Mar 19 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Doug Farrell | last post by:
Hi all, I'm trying to use the 4Suite xml/xsl tools to transform some XML data into HTML. I'm using some examples from the O'Reilly book "Python and XML" and things are blowing up. Here is the...
7
by: CK | last post by:
Hello, I have the 60 MB XML string and I am coding a program in Visual Basic to run a XSL transformation on it. Currently, I'm using the Microsoft standard MSXML 2.0 to create a DOM document, load...
1
by: Eric | last post by:
I am trying to figure out a good way to implement a XSLT transformation. Basically my goal is that I want to be able to ouput the following XML in a document: <chart type="pie" width="100"...
12
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...
1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
4
by: Asbjørn Ulsberg | last post by:
Sorry for posting to a lot of groups, but I'm not sure what this problem relates to, so I thought it was better to be safe than sorry. Please feel free to set FUT to the proper group when...
3
by: Daniel | last post by:
Are the differences between MSXML and .Net XSL transformation documented online anywhere? Many of my XSL's work in MSXML but transform differently in ..Net XSL transformation.
2
by: TomekR | last post by:
Hello ! I was developing xslt sheet lately and - experimenting - I made mistake resulting in that, the effect of the transformation is not well-formed xml document. I made these tests using...
4
by: =?Utf-8?B?REZC?= | last post by:
Within an XSLT transformation, I'm trying to switch the default namespace within a section of the generated XML document to a shared namespace. This way, the content of this section does not have...
1
by: =?Utf-8?B?R2xlbm4gR29tZXo=?= | last post by:
Does Office Excel 2000 support XSLT transformation of data from XML cause am having problem when the attachment is opened in the client side if the Excels version is in Office 2000 and also its...
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
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,...
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,...
1
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...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.