No results from XML to HTML via XSLT?

Discussion in 'XML' started by Ian Vaughan, Feb 3, 2005.

  1. Ian Vaughan

    Ian Vaughan Guest

    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>
    Ian Vaughan, Feb 3, 2005
    #1
    1. Advertising

  2. <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
    David Carlisle, Feb 3, 2005
    #2
    1. Advertising

  3. Ian Vaughan

    Ian Vaughan Guest

    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>


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Ian Vaughan, Feb 3, 2005
    #3
  4. 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
    David Carlisle, Feb 3, 2005
    #4
  5. Ian Vaughan

    Ian Vaughan Guest

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



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Ian Vaughan, Feb 4, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Blue Gecko
    Replies:
    1
    Views:
    442
    Blue Gecko
    Oct 3, 2005
  2. Lenny Wintfeld
    Replies:
    0
    Views:
    733
    Lenny Wintfeld
    May 17, 2006
  3. stew dean

    Email HTML form results via ASPX

    stew dean, Mar 2, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    902
    stew dean
    Mar 2, 2007
  4. Erik Wasser
    Replies:
    5
    Views:
    445
    Peter J. Holzer
    Mar 5, 2006
  5. elsigh
    Replies:
    3
    Views:
    215
    elsigh
    Jul 23, 2006
Loading...

Share This Page