No results from XML to HTML via XSLT?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ian Vaughan

    No results from XML to HTML via XSLT?

    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:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output method="html" />
    <xsl:template match="/">
    <html>
    <head>
    <title>Buildi ng Control</title>
    </head>
    <body>
    <h3>Building Control</h3>
    <table border="0" width="80%" cellpadding="2" cellspacing=
    "1" bgcolor="#99999 9">
    <tr bgcolor="#deded e">
    <th>Scheme</th>
    </tr>
    <xsl:for-each select="SchemeN ame">
    <tr bgcolor="#fffff f">
    <td><xsl:valu e-of select="SchemeN ame" /></td>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

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

    This is my XML Schema

    <?xml version="1.0" encoding="UTF-16" ?>
    - <BuildingRecord Set xmlns:rs="urn:s chemas-microsoft-com:rowset"
    xmlns:z="#Rowse tSchema"
    xmlns:apd="http ://www.govtalk.gov .uk/people/AddressAndPerso nalDetails">
    <SchemeName>DAT A</SchemeName>
    <LocalAuthority Code>DATA</LocalAuthorityC ode>
    - <BuildingRecord >
    <SchemeUniqueRe cordIdentifier> 2</SchemeUniqueRec ordIdentifier>
    <CompetentPerso n>
    <PersonRegistra tionNumber>02</PersonRegistrat ionNumber>
    <InstallerRegis teredName>Name</InstallerRegist eredName>
    </CompetentPerson >
    <WorkPerforme d>
    <PropertyInform ation>
    <PropertyLocati on>
    <PropertyAddres s>
    <apd:A_5LineAdd ress>
    <apd:Line>Ban k</apd:Line>
    <apd:Line />
    <apd:Line />
    <apd:Line></apd:Line>
    <apd:PostCode ></apd:PostCode>
    </apd:A_5LineAddr ess>
    </PropertyAddress >
    </PropertyLocatio n>
    </PropertyInforma tion>
    <DateWorkComple ted>20/01/2005</DateWorkComplet ed>
    <DescriptionOfW orkItem>Shower</DescriptionOfWo rkItem>
    </WorkPerformed>
    </BuildingRecord>
    </buildingrecords et>
  • David Carlisle

    #2
    Re: No results from XML to HTML via XSLT?


    <xsl:template match="/">

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

    <xsl:for-each select="SchemeN ame">

    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 BuildingRecordS et


    probably you just want to change your
    match="/"
    to
    match="Building RecordSet"

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

    If you do that then

    <xsl:for-each select="SchemeN ame">

    would select all the SchemeName children but then
    <td><xsl:valu e-of select="SchemeN ame" /></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:valu e-of select="SchemeN ame" /></td>

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

    <xsl:for-each select="SchemeN ame">
    <tr bgcolor="#fffff f">
    <td><xsl:valu e-of select="." /></td>



    David

    Comment

    • Ian Vaughan

      #3
      Re: No results from XML to HTML via XSLT?

      David

      By replacing the / with BuildingRecordS et
      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="#99999 9">
      <tr bgcolor="#deded e">
      <th colspan="2">Bui lding Record</th>
      </tr>

      <tr bgcolor="#fffff f">
      <xsl:for-each select="SchemeU niqueRecordIden tifier">
      <td>
      <xsl:value-of select="SchemeU niqueRecordIden tifier" />
      </td>
      </xsl:for-each>

      <xsl:for-each select="PersonR egistrationNumb er"">
      <td>
      <xsl:value-of select="PersonR egistrationNumb er" />
      </td>
      </xsl:for-each>
      </tr>
      </table>


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • David Carlisle

        #4
        Re: No results from XML to HTML via XSLT?



        same mistake as before:

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


        so you want either


        <xsl:for-each select="SchemeU niqueRecordIden tifier">
        <td>
        <xsl:value-of select="." />
        </td>
        </xsl:for-each>

        or if you only have one such element,

        <td>
        <xsl:value-of select="SchemeU niqueRecordIden tifier" />
        </td>


        and this is same again:-):

        <xsl:for-each select="PersonR egistrationNumb er"">
        <td>
        <xsl:value-of select="PersonR egistrationNumb er" />
        </td>
        </xsl:for-each>

        David

        Comment

        • Ian Vaughan

          #5
          Re: No results from XML to HTML via XSLT?

          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!

          Comment

          Working...