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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transforming to HTML

Status
Not open for further replies.

tabmow

Programmer
Sep 20, 2005
1
AU
The files i am using are below and it makes the HTML file through xml writer but the customer-family-name and customer-status templates don't match and i can't find the problem. Any help would be much appreciated, thankyou.

XMLPage2.xml is below

<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="XMLPage3.xsl"?>

<customers>
<customer-record>
<customer-account-no>
CUS Ac 0001-A
</customer-account-no>
<customer-name id='c001'>
<customer-family-name>
Phillips
</customer-family-name>
<customer-given-name>
John
</customer-given-name>
</customer-name>
<customer-address>
<customer-address-line-1>
54 Whitebrook Road Malvern
</customer-address-line-1>
<customer-address-city state="VIC">
Melbourne
</customer-address-city>
<customer-address-postcode country="Australia">
3172
</customer-address-postcode>
</customer-address>
<customer-contacts>
<customer-phone-home>
95357574
</customer-phone-home>
<customer-phone-work>
94674743
</customer-phone-work>
<customer-phone-mobile>
0535356432
</customer-phone-mobile>
<customer-fax>
946747434
</customer-fax>
<customer-email id='c001'>
john@phillips.com
</customer-email>
</customer-contacts>
<customer-details>
<customer-join>
2001-09-05
</customer-join>
<customer-status>
C
</customer-status>
<customer-comments>
They call him Johnny, Johnny Phillips!
</customer-comments>
</customer-details>
</customer-record>
</customers>


XMLPage3.xsl file is below:

<?xml version="1.0"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl=" xmlns="
<!-- Root Element -->
<xsl:template match="/">
<html>
<head>
<title>Customer Reporting Page</title>
</head>
<body bgcolor="white">
<center><h1>Customer Report</h1></center>
<xsl:apply-templates select="customers" />
</body>
</html>
</xsl:template>

<!-- Matches the root element of Customers -->
<xsl:template match="customers">
<table border="1" cellspacing="5" cellpadding="1" align="center">

<tr bgcolor="black" align="left">
<th><font color = "white">Account no</font></th>
<th><font color = "white">Family name</font></th>
<th><font color = "white">Given name</font></th>
<th><font color = "white">Email address</font></th>
<th><font color = "white">Status</font></th>
</tr>

<xsl:for-each select="customer-record">
<tr>
<td>
<xsl:value-of select="customer-account-no"/>
</td>
<td>
<xsl:apply-templates select="customer-name/customer-family-name"/>
</td>
<td>
<xsl:value-of select="customer-name/customer-given-name"/>
</td>
<td>
<xsl:value-of select="customer-contacts/customer-email"/>
</td>
<td>
<xsl:apply-templates select="customer-details/customer-status"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>

<!-- Matches Customer Status in order to do the asterixes -->
<xsl:template match="customer-status">
<xsl:choose>
<xsl:when test=". = 'C'">
<xsl:value-of select="."/>
<font color="green">
*****
</font>
</xsl:when>

<xsl:when test=". = 'D'">
<xsl:value-of select="."/>
<font color="red">
*****
</font>
</xsl:when>

<xsl:eek:therwise>
<xsl:value-of select="."/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

<!-- Matches Family Name to change colour of first letter -->
<xsl:template match="customer-family-name">
<xsl:for-each select=".">
<font color="blue">
<xsl:value-of select="substring(.,1,1)"/>
</font>
<xsl:value-of select="substring(.,2,50)"/>
<xsl:message>In template family name</xsl:message>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
 
Those templates do match. You definitely using that input XML?

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top