Jump to content

How To Display Multiple Subordinate Items From An Xml File In A Web Page?


ReddetEkim

Recommended Posts

Hi. After a lot of studying I've learned how to create valid xml schemas and data files, and I've been able to display some of that data on a web page but not all of it. For example, if there are multiple <city> nodes under a <state> node, I've been able to display all of the state nodes in the file using "for-each select" and "value-of select", but only the first city in each state; none of the other cities. How do I display multiple items at a subordinate level like cities in a state? Thanks.

Link to comment
Share on other sites

Actually, none of the subordinate items are appearing. When I added another select for the subordinate items, the original, superior items were no longer displayed. Code is included below. Thanks for any help you can provide. XSL file: <?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html><head><title>Mexican States and Capitals</title><!-- <link rel="stylesheet" type="text/css" href="Test.css" /> --></head><body><h1>Mexican States and Capitals</h1><p id="date"></p><br /><!-- <script type="text/javascript" src="displaydate.js"></script> --><!-- Select State works well--><xsl:for-each select="mexican_states/mexican_state"><p><b>State: </b><xsl:value-of select="state_name"/>(<xsl:value-of select="abbreviation"/>)<br /><b>Capital: </b><xsl:value-of select="state_capital"/><br /><xsl:value-of select="state_notes"/><!-- Select City within State does not work at all--><xsl:for-each select="mexican_states/mexican_state/mexican_city"><b>Cities: </b><xsl:value-of select="city_name"/><xsl:value-of select="city_notes"/></xsl:for-each></p></xsl:for-each><a href="Home_Page.htm">Home Page</a><br /></body></html></xsl:template></xsl:stylesheet> XSD Schema file: <?xml version="1.0" encoding="ISO-8859-1"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="mexican_states"> <xs:complexType> <xs:sequence> <xs:element name="mexican_state" minOccurs="0" maxOccurs="32"> <xs:complexType> <xs:sequence> <xs:element name="state_name" type="xs:string" minOccurs="0" maxOccurs="1" /> <xs:element name="abbreviation" type="xs:string" minOccurs="0" maxOccurs="1" /> <xs:element name="state_capital" type="xs:string" minOccurs="0" maxOccurs="1" /> <xs:element name="state_notes" type="xs:string" minOccurs="0" maxOccurs="1" /> <xs:element name="mexican_city" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="city_name" type="xs:string" minOccurs="0" maxOccurs="1" /> <xs:element name="city_notes" type="xs:string" minOccurs="0" maxOccurs="1" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element></xs:schema> XML data file edited for brevity. Multiple states are included in the original file. <?xml version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet type="text/xsl" href="Test.xsl"?><mexican_states xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="Test.xsd"><mexican_state><state_name>Jalisco</state_name><abbreviation>Jal</abbreviation><state_capital>Guadalajara*</state_capital><state_notes></state_notes><mexican_city><city_name>Acapulco</city_name><city_notes></city_notes></mexican_city><mexican_city><city_name>Guadalajara</city_name><city_notes></city_notes></mexican_city><mexican_city><city_name>Puerto Vallarta</city_name><city_notes></city_notes></mexican_city></mexican_state></mexican_states>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...