RE: [xsl] Data not displaying in HTML table...generated from XML

Subject: RE: [xsl] Data not displaying in HTML table...generated from XML
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Tue, 28 Oct 2003 23:43:29 -0000
A path expression beginning with "/" selects the root node of the
document containing the context node. In your template with
match="metadata", the expression "/page-links" will not select anything.

Define a global variable <xsl:variable name="root" select="/"/> and then
use $root/page-links, which will get you back to the principal source
document whatever you are currently processing.

But if you do that, then this:

<xsl:template match="metadata">  
 <xsl:for-each select="$root/page-links/page-link">  
     <xsl:apply-templates select="document(@filename)/metadata"/>  
 </xsl:for-each>

is going to give you an infinite loop. I don't actually know what you
are trying to achieve here.

Michael Kay


> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Bill Walker
> Sent: 28 October 2003 18:36
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Data not displaying in HTML table...generated from XML
> 
> 
> Hi
>  
> I am quite new to XML and XSL and still make frequent XSL mistakes.   
>  
> I often can't see why my output to HTML doesn't produce what I want.
>  
> Here is my latest little puzzle:
>  
> Here is the XML file being processed and one example XML file 
> that the document funtion points to:
>  
> all-links-master-list.xml
>  
> <?xml version="1.0" encoding="ISO-8859-1"?>
>  
> <page-links xmlns:dc="http://purl.org/dc/elements/1.1/";>
>  
>    <page-link filename="american-factfinder.xml"/>
>    <page-link filename="ask-eric.xml"/>
>    <page-link filename="biog-com.xml"/>
>    <page-link filename="bur-just-stats.xml"/>
>    <page-link filename="bureau-labor-stats.xml"/>
>    <page-link filename="bus-stats-web.xml"/>
>    <page-link filename="cal-dept-finance.xml"/>
>    <page-link filename="calif-crime-index.xml"/>
>    <page-link filename="calif-city-profiles.xml"/>
>  
> </page-links>
>  
> one example file...  american-factfinder.xml
>  
> <?xml version="1.0"?>
> <metadata
>   xmlns:dc="http://purl.org/dc/elements/1.1/";>
>     <dc:title>
>       American FactFinder
>     </dc:title>
>     <dc:creator>
>       U.S. Census Bureau
>     </dc:creator>
>     <dc:description>
>       Population, housing,
>       economic and geographic data from Census 2000, the 1990
>       Census, the 1997 Economic Census, the Census 2000
>       Supplementary Survey, and the American Community Survey
>     </dc:description>
>     <dc:date>
>       20030904 viewed bw
>     </dc:date>
>     <dc:type>
>       Text
>     </dc:type>
>     <dc:format>
>       text/html
>     </dc:format>
>     <dc:format>
>       34504 bytes
>     </dc:format>
>      
> <dc:identifier>http://factfinder.census.gov/servlet/BasicFacts
> Servlet</dc:identifier>
>      <dc:relation type="IsPartof">stat-openpg.htm</dc:relation>
>     <dc:relation type="IsPartof">stat-gensit.htm</dc:relation>
>     <dc:relation type="IsPartof">stat-pop.htm</dc:relation>
>     <name-of-xml-file>american-factfinder.xml</name-of-xml-file>
> </metadata>
> 
>  
> Here is the XSL file...   all-links-master-list.xsl
>  
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> version="1.0"
> xmlns:dc="http://purl.org/dc/elements/1.1";>
>  
> <xsl:output method="html"/>
>  
> <xsl:template match="/">
>   
>     <html>
>     
>    <body>
>  
>      <table width="95%" border="1" cellspacing="1" cellpadding="5">
>    
>        <tr bgcolor="yellow">
>   
>       <th>URL</th>
>     
>       <th>Name</th>
>     
>       <th>Name of XML file</th>
>     
>       <th>Included on page:</th>
>     
>     </tr>
>   
> <xsl:for-each select="/page-links/page-link">
>  
>     <xsl:apply-templates select="document(@filename)/metadata"/>
>   
> </xsl:for-each>
>  
>         </table>
>    
>     </body>
>   
>    </html>
>    
> </xsl:template>
>  
> 
> <xsl:template match="metadata">
>  
> <xsl:for-each select="/page-links/page-link">
>  
>     <xsl:apply-templates select="document(@filename)/metadata"/>
>   
> </xsl:for-each>
>  
>      <tr>
>      
>        <td><xsl:value-of select="dc:identifier"/></td>
>   
>        <td><xsl:value-of select="dc:title"/></td>
>   
>        <td><xsl:value-of select="name-of-xml-file"/></td>
>   
>        <td><xsl:for-each select="dc:relation"><xsl:value-of
> select="."/><br/></xsl:for-each></td>
>  
>     </tr>
>  
> </xsl:template> 
>                
> </xsl:stylesheet>
>  
> and the resulting HTML file:  all-links-master-list.htm
>  
> <html xmlns:dc="http://purl.org/dc/elements/1.1";>
>    <body>
>       <table width="95%" border="1" cellspacing="1" cellpadding="5">
>          <tr bgcolor="yellow">
>             <th>URL</th>
>             <th>Name</th>
>             <th>Name of XML file</th>
>             <th>Included on page:</th>
>          </tr>
>          <tr>
>             <td></td>
>             <td></td>
>             <td>american-factfinder.xml</td>
>             <td></td>
>          </tr>
>          <tr>
>             <td></td>
>             <td></td>
>             <td>ask-eric.xml</td>
>             <td></td>
>          </tr>
>          <tr>
>             <td></td>
>             <td></td>
>             <td>biog-com.xml</td>
>             <td></td>
>          </tr>
>          <tr>
>             <td></td>
>             <td></td>
>             <td>bur-just-stats.xml</td>
>             <td></td>
>          </tr>
>          <tr>
>             <td></td>
>             <td></td>
>             <td>bureau-labor-stats.xml</td>
>             <td></td>
>          </tr>
>          <tr>
>             <td></td>
>             <td></td>
>             <td>bus-stats-web.xml</td>
>             <td></td>
>          </tr>
>          <tr>
>             <td></td>
>             <td></td>
>             <td>cal-dept-finance.xml</td>
>             <td></td>
>          </tr>
>          <tr>
>             <td></td>
>             <td></td>
>             <td>calif-crime-index.xml</td>
>             <td></td>
>          </tr>
>       </table>
>    </body>
> </html>
>  
>  
> As you can see, it gets one table data correct in each row, 
> but not the other ones.
>  
> Can someone please help me figure this out?   I have looked 
> at this for
> quite
> a long time and can't see the mistake.   And again, being new at this,
> I have probably done some inefficient XSL thing which may not 
> be "best practice" or is redundant or something.
>  
> Please let me know the best way to approach this and fix it.
>  
> Thanks to anyone who has a little time and would like to do 
> the diagnosis.
>  
> I would think any old-time XSL wizards will spot the problem 
> right away.
>  
> --Bill Walker
>   Reference Dept.
>   Stockton-San Joaquin County Public Library
> 
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread