views:

63

answers:

4

Hi,

I am trying to display xml data in html via XSLT.

I am building a simple html table that displays a Name, Address, & Phone Number.

The XSL template pulls the Name & Phone Number, but for some reason, it won't grab the Address.

Please help, thanks in advance.

XML Doc

<?xml-stylesheet type="text/xsl" href="testreport.xsl"?>
<BpsReportResponse>
   <Individual>
      <HistoricalNeighbors>
        <Neighborhood>
            <NeighborAddresses>
               <NeighborAddress>
                  <Address>
                     <StreetName>SOMESTREET</StreetName>
                     <City>SOMECITY</City>
                     <County>SOMECOUNTY</County>
                     <State>NJ</State>
                     <StreetNumber>999</StreetNumber>
                     <Zip5>00000</Zip5>
                     <Zip4>0000</Zip4>
                     <StreetSuffix>ST</StreetSuffix>
                  </Address>
                  <DateLastSeen>
                     <Year>2008</Year>
                  </DateLastSeen>
                  <DateFirstSeen>
                     <Month>3</Month>
                     <Year>1996</Year>
                  </DateFirstSeen>
                  <Residents>
                     <Identity>
                        <Name>
                           <Last>DOE</Last>
                           <First>JANE</First>
                        </Name>
                        <UniqueId>00000000000</UniqueId>
                     </Identity>
                  </Residents>
                  <LocationId></LocationId>
                  <Phones>
                     <Phone>
                        <Phone10>9999999999</Phone10>
                     </Phone>
                  </Phones>
               </NeighborAddress>               
            </NeighborAddresses>
         </Neighborhood>
      </HistoricalNeighbors>
   </Individual>   
</BpsReportResponse>


XSL Template

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
<xsl:output method="html"/>
<xsl:template match="BpsReportResponse/Individual"> 
    <html>
    <head>
     <link rel="stylesheet" type="text/css" href="stylesheet.css" />

    </head>
    <body> 

     <div id="neighbors">
      <table>
       <tr class="header"><td colspan="3">Neighbors</td></tr>
       <tr class="subheader">
        <td>Name</td>
        <td>Address</td>
        <td>Phone</td>
       </tr>
       <xsl:for-each select="HistoricalNeighbors/Neighborhood/NeighborAddresses/NeighborAddress">
        <tr>                        
         <td>                            
          <xsl:value-of select="Residents/Identity/Name/First"/>&#160;<xsl:value-of select="Residents/Identity/Name/Middle"/>&#160;<xsl:value-of select="Residents/Identity/Name/Last"/> 
         </td>
         <td>     
          <xsl-value-of select="Address/StreetNumber"/>&#160;<xsl-value-of select="Address/StreetName"/>&#160;<xsl-value-of select="Address/StreetSuffix"/>, 
          <xsl-value-of select="Address/City"/>,&#160;<xsl-value-of select="Address/State"/>&#160;<xsl-value-of select="Address/Zip5"/>
         </td>
         <td><xsl:value-of select="Phones/Phone/Phone10"/></td>
        </tr>
       </xsl:for-each>
      </table>
     </div>

    </body>
    </html>  
</xsl:template>
</xsl:stylesheet>
+4  A: 

You did xsl-value-of instead of xsl:value-of for the address elements.

Go get Xselerator from Sourceforge, it is an awesome tool for doing stuff like this. I copied and pasted your stuff into it and I saw the error immediately.

Darrel Miller
A: 

You'll sh*t bricks:

Change:

<xsl-value-of select="Address/StreetNumber"/>

for

<xsl:value-of select="Address/StreetNumber"/>
Rubens Farias
A: 

Note that <xsl-value-of ...> isn't a formal error, it's just not what you wanted! It's simply taken as another output element by XSLT and if you look at the output you will see it there along with the select attribute! XSLT assumes you mean what you input - if you get no results because you have typed something wrong, then XSLT makes no comment - why should it. It means it fails gracefully most of the time but often silently.

peter.murray.rust
+1  A: 

visual studio is also a good editor for xslt,It shows all errors so it becomes much easier to find bugs.

Thunder