I’m very new to XML and XSLT. I have a homework assignment that asks us to generate a page based on some XML data. It’s pretty straightforward, so here it goes:
My XML data looks like this:
<convention>
<title>ABC Web Development Conference</title>
<location>ABC College, San Diego, CA</location>
<date> March 25, 2011 - March 27, 2011</date>
<exhibitor>
<name>John Smith</name>
<address1>1234 2nd Avenue</address1>
<address2></address2>
<city>San Diego</city>
<state>CA</state>
<email>john@john.com</email>
<specialization>
<subject>Web Development</subject>
<subject>Software Design</subject>
</specialization>
</exhibitor>
<exhibitor>
<name>Jane Smith</name>
<address1>1234 First Avenue</address1>
<address2>Ste 123</address2>
<city>San Diego</city>
<state>CA</state>
<email>jane@jane.com</email>
<specialization>
<subject>Web Development</subject>
</specialization>
</exhibitor>
</convention>
Basically, I’ve set it up to output into a table nicely. My problem comes up when I output address 2. I want to make it so that if the string-length of address2 is greater then 0, output a comma.
Here is what my XSL data looks like:
<table width="600" border="1" cellspacing="3" cellpadding="5">
<tr>
<td colspan="3" align="center"><xsl:value-of select="convention/title"/></td>
</tr>
<tr>
<td colspan="3" align="center"><xsl:value-of select="convention/location"/></td>
</tr>
<tr>
<td colspan="3" align="center"><xsl:value-of select="convention/date"/></td>
</tr>
<tr>
<th>Exhibitor</th>
<th>Address</th>
<th>Specialization</th>
</tr>
<xsl:for-each select="convention/exhibitor">
<tr>
<td><xsl:value-of select="name"/><br /><xsl:value-of select="email"/></td>
<td><xsl:value-of select="address1"/>, <xsl:value-of select="address2"/> <xsl:value-of select="city"/>, <xsl:value-of select="state"/></td>
<td><xsl:for-each select="specialization/subject"><xsl:value-of select="."/><br /></xsl:for-each></td>
</tr>
</xsl:for-each>
<tr>
<td colspan="3">Total Number of Exhibitors: <xsl:value-of select="count(convention/exhibitor)"/></td>
</tr>
</table>
Any assistance is greatly appreciated 🙂
Do you have a course book? I will give you some hints that may help you in locating the information you need:
xsl:if)If you are unfamiliar with these concepts, I suggest you to look more information from your course material.
Good luck!