No results from XML to HTML via XSLT?

I

Ian Vaughan

Any ideas why I am not getting any results back in my HTML via XSLT
from my XML doc. It is not returning any errors just no matches when
it should return a value of DATA for SchemeName ??


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="html" />
<xsl:template match="/">
<html>
<head>
<title>Building Control</title>
</head>
<body>
<h3>Building Control</h3>
<table border="0" width="80%" cellpadding="2" cellspacing=
"1" bgcolor="#999999">
<tr bgcolor="#dedede">
<th>Scheme</th>
</tr>
<xsl:for-each select="SchemeName">
<tr bgcolor="#ffffff">
<td><xsl:value-of select="SchemeName" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

----------------------------------------

This is my XML Schema

<?xml version="1.0" encoding="UTF-16" ?>
- <BuildingRecordSet xmlns:rs="urn:schemas-microsoft-com:rowset"
xmlns:z="#RowsetSchema"
xmlns:apd="http://www.govtalk.gov.uk/people/AddressAndPersonalDetails">
<SchemeName>DATA</SchemeName>
<LocalAuthorityCode>DATA</LocalAuthorityCode>
- <BuildingRecord>
<SchemeUniqueRecordIdentifier>2</SchemeUniqueRecordIdentifier>
<CompetentPerson>
<PersonRegistrationNumber>02</PersonRegistrationNumber>
<InstallerRegisteredName>Name</InstallerRegisteredName>
</CompetentPerson>
<WorkPerformed>
<PropertyInformation>
<PropertyLocation>
<PropertyAddress>
<apd:A_5LineAddress>
<apd:Line>Bank</apd:Line>
<apd:Line />
<apd:Line />
<apd:Line></apd:Line>
<apd:postCode></apd:postCode>
</apd:A_5LineAddress>
</PropertyAddress>
</PropertyLocation>
</PropertyInformation>
<DateWorkCompleted>20/01/2005</DateWorkCompleted>
<DescriptionOfWorkItem>Shower</DescriptionOfWorkItem>
</WorkPerformed>
</BuildingRecord>
</buildingrecordset>
 
D

David Carlisle

<xsl:template match="/">

so here the current node is / representing the whole document.

<xsl:for-each select="SchemeName">

this selects SchemeName children of the docuemnt node, there are none,
tehre can only be one element node child of / in a well formed document
and in this case that's BuildingRecordSet


probably you just want to change your
match="/"
to
match="BuildingRecordSet"

(the default template for / will apply templates to its children)

If you do that then

<xsl:for-each select="SchemeName">

would select all the SchemeName children but then
<td><xsl:value-of select="SchemeName" /></td>

would generate an empty td as there are no SchemeName children of the
current node at that point (which is SchemeName)

If you only have one SchemeName element get rid of the for-each and do

<td><xsl:value-of select="SchemeName" /></td>

or if you have more than one and you want a td for each of them do

<xsl:for-each select="SchemeName">
<tr bgcolor="#ffffff">
<td><xsl:value-of select="." /></td>



David
 
I

Ian Vaughan

David

By replacing the / with BuildingRecordSet
has returned the data.

I have added the following table to retrieve more data from the XML Doc
but again it is returning no results just empty table cells ??

<table border="0" width="80%" cellpadding="2" cellspacing="1"
bgcolor="#999999">
<tr bgcolor="#dedede">
<th colspan="2">Building Record</th>
</tr>

<tr bgcolor="#ffffff">
<xsl:for-each select="SchemeUniqueRecordIdentifier">
<td>
<xsl:value-of select="SchemeUniqueRecordIdentifier" />
</td>
</xsl:for-each>

<xsl:for-each select="PersonRegistrationNumber"">
<td>
<xsl:value-of select="PersonRegistrationNumber" />
</td>
</xsl:for-each>
</tr>
</table>
 
D

David Carlisle

same mistake as before:

<xsl:for-each select="SchemeUniqueRecordIdentifier">
so here current node is SchemeUniqueRecordIdentifier
<td>
<xsl:value-of select="SchemeUniqueRecordIdentifier" />
this is looking for a SchemeUniqueRecordIdentifier child of the
current node, when actually you want the current node not its
child. this will only be non-empty of you have
<SchemeUniqueRecordIdentifier>
<SchemeUniqueRecordIdentifier>
...
</SchemeUniqueRecordIdentifier>
</SchemeUniqueRecordIdentifier>
</td>


so you want either


<xsl:for-each select="SchemeUniqueRecordIdentifier">
<td>
<xsl:value-of select="." />
</td>
</xsl:for-each>

or if you only have one such element,

<td>
<xsl:value-of select="SchemeUniqueRecordIdentifier" />
</td>


and this is same again:):

<xsl:for-each select="PersonRegistrationNumber"">
<td>
<xsl:value-of select="PersonRegistrationNumber" />
</td>
</xsl:for-each>

David
 
I

Ian Vaughan

Do you have any examples I can follow of converting the XML doc into a
fixed width CSV file ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top