Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Advice on XSL style sheet for XML file

Status
Not open for further replies.

ad2

Technical User
Dec 31, 2002
186
US
Hi,

I have my XML file and XSL styleshhet. It is working fine except for one bug in the XSL file.

The XML file will be a list of libraries in each county. Only have 2 counties now for design.

I want the XSL file to display the first county and all the libraries in that county, and then display the next county and all the libraries in that county, just like the XML file is set up. Any help would be great.

Here is the XML file:
<?xml version="1.0" ?>
<?xml:stylesheet type="text/xsl" href="Libraries.xsl"?>
<LIBRARIES>

<COUNTY>
<COUNTY_NAME>Boone</COUNTY_NAME>
<LIBRARY>
<LIBRARY_NAME>The Hussey-Mayfield Memorial Public Library</LIBRARY_NAME>
<ADDRESS>250 N. 5th St.</ADDRESS>
<CITY>Zionsville</CITY>
<STATE>IN</STATE>
<ZIP>46077</ZIP>
<PHONE>(317) 873-3149</PHONE>
<FAX>(317) 873-8339</FAX>
<WEB> <NOTES>Test of Library Resources Page</NOTES>
</LIBRARY>

<LIBRARY>
<LIBRARY_NAME>Lebanon Public Library</LIBRARY_NAME>
<ADDRESS>104 E Washington St.</ADDRESS>
<CITY>Lebanon</CITY>
<STATE>IN</STATE>
<ZIP>46052</ZIP>
<PHONE>(765) 482-3460</PHONE>
<FAX>(317) 873-5059 </FAX>
<WEB> </LIBRARY>

<LIBRARY>
<LIBRARY_NAME>Thorntown Public Library</LIBRARY_NAME>
<ADDRESS>124 N. Market St.</ADDRESS>
<CITY>Thorntown</CITY>
<STATE>IN</STATE>
<ZIP>46071</ZIP>
<PHONE>(765) 436-7348</PHONE>
<FAX>(765) 436-7011</FAX>
<WEB> </LIBRARY>
</COUNTY>

<COUNTY>
<COUNTY_NAME>Marion</COUNTY_NAME>
<LIBRARY>
<LIBRARY_NAME>Beech Grove Public Library</LIBRARY_NAME>
<ADDRESS>1102 Main St</ADDRESS>
<CITY>Beech Grove</CITY>
<STATE>IN</STATE>
<ZIP>46107</ZIP>
<PHONE>(317) 788-4203</PHONE>
<WEB> </LIBRARY>

<LIBRARY>
<LIBRARY_NAME>Butler University Libraries</LIBRARY_NAME>
<ADDRESS>4600 Sunset Ave.</ADDRESS>
<CITY>Indianapolis</CITY>
<STATE>IN</STATE>
<ZIP>46208</ZIP>
<PHONE>(317) 940-9227</PHONE>
<WEB> </LIBRARY>

<LIBRARY>
<LIBRARY_NAME>Christian Theological Seminary Library</LIBRARY_NAME>
<ADDRESS>1000 W. 42nd St.</ADDRESS>
<CITY>Indianapolis</CITY>
<STATE>IN</STATE>
<ZIP>46208</ZIP>
<PHONE>(317) 924-1331</PHONE>
<FAX>(317) 923-1961</FAX>
<WEB> </LIBRARY>

<LIBRARY>
<LIBRARY_NAME>Indiana Historical Society Library</LIBRARY_NAME>
<ADDRESS>450 West Ohio St.</ADDRESS>
<CITY>Indianapolis</CITY>
<STATE>IN</STATE>
<ZIP>46202</ZIP>
<PHONE>(317) 232-1882</PHONE>
<WEB> </LIBRARY>

<LIBRARY>
<LIBRARY_NAME>Indiana University-Purdue University Indianapolis Libraries</LIBRARY_NAME>
<ADDRESS>755 West Michigan St.</ADDRESS>
<CITY>Indianapolis</CITY>
<STATE>IN</STATE>
<ZIP>46202-5195</ZIP>
<PHONE>(317) 274-8278</PHONE>
<WEB> </LIBRARY>

<LIBRARY>
<LIBRARY_NAME>Indiana Wesleyan University Libraries</LIBRARY_NAME>
<ADDRESS>4201 S Washington St.</ADDRESS>
<CITY>Marion</CITY>
<STATE>IN</STATE>
<ZIP>46953-4999</ZIP>
<PHONE>(765)674-6901</PHONE>
<WEB> </LIBRARY>

<LIBRARY>
<LIBRARY_NAME>Indianapolis Marion County Public Library System</LIBRARY_NAME>
<ADDRESS>PO Box 211</ADDRESS>
<CITY>Indianapolis</CITY>
<STATE>IN</STATE>
<ZIP>46206</ZIP>
<PHONE>(317) 269-1700</PHONE>
<WEB> </LIBRARY>

<LIBRARY>
<LIBRARY_NAME>Marian College Library</LIBRARY_NAME>
<ADDRESS>3200 Cold Spring Rd.</ADDRESS>
<CITY>Indianapolis</CITY>
<STATE>IN</STATE>
<ZIP>46222-1997</ZIP>
<PHONE>(317) 955-6000</PHONE>
<WEB> </LIBRARY>

<LIBRARY>
<LIBRARY_NAME>Speedway Public Library</LIBRARY_NAME>
<ADDRESS>5633 W. 25th St.</ADDRESS>
<CITY>Speedway</CITY>
<STATE>IN</STATE>
<ZIP>46224</ZIP>
<PHONE>(317) 243-8959</PHONE>
<FAX>(317) 243-9373</FAX>
<WEB> </LIBRARY>

<LIBRARY>
<LIBRARY_NAME>University of Indianapolis Library</LIBRARY_NAME>
<ADDRESS>1400 East Hanna Ave.</ADDRESS>
<CITY>Indianapolis</CITY>
<STATE>IN</STATE>
<ZIP>46227</ZIP>
<PHONE>(317) 788 3268</PHONE>
<WEB> </LIBRARY>
</COUNTY>
</LIBRARIES>

And Here is the XSL file:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=" version="1.0">
<xsl:template match="/">
<html>
<body>

<table><xsl:for-each select="//COUNTY">
<tr><td> <font size="+1" color="+330099"><b><i><xsl:value-of select="COUNTY_NAME"/>
<xsl:text> County</xsl:text> </i></b></font>
</td>
</tr>
</xsl:for-each>
<xsl:for-each select="//COUNTY/LIBRARY">
<tr>
<td bgcolor="#99ccff"><b><xsl:value-of select="LIBRARY_NAME"/></b>
</td></tr>
<tr>
<td><xsl:value-of select="ADDRESS"/><br/>
<xsl:value-of select="CITY"/>,<xsl:text> </xsl:text>
<xsl:value-of select="STATE"/><xsl:text> </xsl:text>
<xsl:value-of select="ZIP"/><br/>
<xsl:text>Phone: </xsl:text><xsl:value-of select="PHONE"/><br/>
<xsl:text>FAX: </xsl:text><xsl:value-of select="FAX"/><br/>
<xsl:text> Web: </xsl:text>
<a><xsl:attribute name="href">
<xsl:text> select="WEB"/></xsl:attribute>
<i><xsl:value-of select="WEB"/></i>
</a><br/>
<xsl:value-of select="NOTES"/><br/>
<p> </p>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
 
You could nest the <xsl:for-each...> elements:

<xsl:for-each select="//COUNTY">
...
<xsl:for-each select="LIBRARY">
...
</xsl:for-each>
</xsl:for-each>

Mind you: <xsl:for-each select="//COUNTY/LIBRARY"> like you used means: for each LIBRARY in any COUNTY...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top