NullReference
NullReference

Reputation: 93

XSL Template, some data not being pulled

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.

<?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>

testreport.xsl

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<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>

Upvotes: 0

Views: 163

Answers (4)

Thunder
Thunder

Reputation: 11016

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

Upvotes: 0

peter.murray.rust
peter.murray.rust

Reputation: 38063

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.

Upvotes: 0

Rubens Farias
Rubens Farias

Reputation: 57976

You'll sh*t bricks:

Change:

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

for

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

Upvotes: 0

Darrel Miller
Darrel Miller

Reputation: 142174

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.

Upvotes: 3

Related Questions