homepage Welcome to WebmasterWorld Guest from 54.211.73.232
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
XSL layout Help
XML to HTML Table via XSL
poisontheused

10+ Year Member



 
Msg#: 23 posted 4:52 am on Aug 16, 2004 (gmt 0)

I'm attempting to display the following XML code in an HTML table using an XSL stylesheet. but am having a few problems.

First off an extract from the XML which was generated using Crystal Reports


<FormattedSections>
<FormattedSection SectionNumber="0">
<FormattedReportObjects>
<FormattedReportObject xsi:type="CTFormattedField" Type="xsd:string" FieldName="{VhStock.REGNO}"><ObjectName>Field22</ObjectName>
<FormattedValue>RLF462</FormattedValue>
<Value>RLF462</Value>
</FormattedReportObject>
<FormattedReportObject xsi:type="CTFormattedField" Type="xsd:string" FieldName="{VhStock.BODY_TYPE}"><ObjectName>Field25</ObjectName>
<FormattedValue>SEDAN</FormattedValue>
<Value>SEDAN</Value>
</FormattedReportObject>
<FormattedReportObject xsi:type="CTFormattedField" Type="xsd:string" FieldName="{VhStock.TRANSMISSION}"><ObjectName>Field27</ObjectName>
<FormattedValue>5M</FormattedValue>
<Value>5M</Value>
</FormattedReportObject>
<FormattedReportObject xsi:type="CTFormattedField" Type="xsd:string" FieldName="{VhStock.PAINT}"><ObjectName>Field28</ObjectName>
<FormattedValue>GREEN</FormattedValue>
<Value>GREEN</Value>

**Note i am wanting to diplay the data between the<Value> </Value> tags in the above XML. How do i select Say just the "VhStock.REGNO" field to display in one <td> and "VhStock.Paint" in the next <td>.

Heres the stylesheet i've created to display the XML it grabs the data but doesnt put it in to a table or any sort of structure plese help:


<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v4.2 -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>Used Vehicles</h2>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="FormattedReportObjects">
<table border="0">
<xsl:apply-templates/>
</table>
</xsl:template>

<xsl:template match="FormattedReportObject">
<tr>
<xsl:apply-templates/>
</tr>
</xsl:template>

<xsl:template match="ObjectNameŠFormattedValueŠValue">
<td>
<xsl:value-of select="text()"/>
</td>
</xsl:template>
</xsl:stylesheet>

when i view this in the browser it displays like this.
--------------------------------------------------------------------------
Used Vehicles
Field26DAEWOODAEWOOField22RLF462RLF462Field25SEDANSEDANField275M5MField28GREENGREENField2906/981998-06-01T00:00:00Field304/02/052005-02-04T00:00:00Field3187,13687136.00Field33BBField34269269.00Field1$7,9957995.00Field2110110.00Field5LAN OS SELANOS
--------------------------------------------------------------------------
So its not displaying it in a table at all.. i have tried following many tutorials but none have helped me so far.

I have checked both the XML and XSL file in an editor and are both well-formed.

I'm just really stuck on this at the moment, mainly because none of the tutorials really relate to an XML document structured like the one above.

Any help would be greatly appreciated.

 

macrost

10+ Year Member



 
Msg#: 23 posted 9:25 pm on Aug 21, 2004 (gmt 0)

poisontheused,
I have created a sample xsl, but it only works for the little snippet that you provided. If the xml file is huge, this xsl is going to be very, very slow.

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<table>
<xsl:call-template name="processme"/>
</table>
</xsl:template>
<xsl:template name="processme">
<tr>
<xsl:for-each select="FormattedSections/FormattedSection/FormattedReportObjects/FormattedReportObject">
<xsl:if test="@FieldName = '{VhStock.REGNO}'">
<td><xsl:value-of select="@FieldName"/></td>
</xsl:if>
<xsl:if test="@FieldName = '{VhStock.PAINT}'">
<td><xsl:value-of select="@FieldName"/></td>
</xsl:if>
</xsl:for-each>
</tr>
<tr>
<xsl:for-each select="FormattedSections/FormattedSection/FormattedReportObjects/FormattedReportObject">
<xsl:if test="@FieldName = '{VhStock.REGNO}'">
<td><xsl:value-of select="Value"/></td>
</xsl:if>
<xsl:if test="@FieldName = '{VhStock.PAINT}'">
<td><xsl:value-of select="Value"/></td>
</xsl:if>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>

Give it a shot, let me know what you think. I know that some people are going to flame this xsl, :) but oh well, it's been a while.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved