I have one XML document (readings.xml) being linked to an XSLT document via JavaScript DOM, and am linking the another (customer.xml) through the select="document('customers.xml')/customers/..." /> method in the XSLT document.
I have this XML document (customer.xml):
Expand|Select|Wrap|Line Numbers
- <customers>
- <customer number="__">
- <meterNumber>
- <title>
- <name>
- <firstName>
- <middleName>
- <lastName>
- </name>
- <address>
- <streetName>
- <suburb>
- <postcode>
- </address>
- <phone>
- <homePhone>
- <workPhone>
- <mobile>
- </phone>
- <history date="29/11/2006">
- <meterReading>
- <amountDue>
- <paid>
- <datePaid>
- <amountPaid>
- </history>
- // MOSTLY HAS MORE THAN ONE HISTORY ELEMENT
- </customer>
- <customer>
- ...
- </customer>
- .
- .
- .
- </customers>
This is what I'm aiming to acheive:
Customer #1 Details
Customer #1 Readings
---------------------------------------------
Customer #2 Details
Customer #2 Readings
etc.
So far with my XSLT I'm getting:
Customer #1 Details
Customer #2 Details
.
.
Customer #n Details
Customer #1 Readings
---------------------------------------------
Customer #1 Details
Customer #2 Details
.
.
Customer #n Details
Customer #2 Readings
etc.
I've been trying to look up loops for a while now but haven't quite got it to work with my documents to what I'm aiming to achieve.
I'm also wondering as to how you find whether two elements (not in the same XML) have the same data in them when they're in different files and different types like attribute + element.
eg. meterNumber (in customers.xml) = meterNumber (in readings.xml)
or @date (in customers.xml) = date (in readings.xml)
Any suggestions to improve my coding or a heads up to where I might be going wrong would be greatly appreciated!
Thanks a bunch! =)
Here's my XSLT:
Expand|Select|Wrap|Line Numbers
- <?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="/">
- <xsl:for-each select="meterReadings/meter">
- <xsl:apply-templates select="document('customers.xml')" />
- <hr />
- // HTML TABLE STUFF
- <xsl:for-each select="customers/customer">
- <tbody>
- <tr>
- <td><strong>Account Number:</strong></td>
- <td><xsl:value-of select="@number" /></td>
- <td><strong>Address:</strong></td>
- <td><xsl:value-of select="address/streetName" /></td>
- </tr>
- <tr>
- <td><strong>Customer Name:</strong></td>
- <td><xsl:value-of select="name/firstName" /><xsl:text> </xsl:text><xsl:value-of select="name/lastName" /></td>
- <td></td>
- <td><xsl:value-of select="address/suburb" /></td>
- </tr>
- <tr>
- <td></td>
- <td></td>
- <td></td>
- <td><xsl:value-of select="address/postcode" /></td>
- </tr>
- </tbody>
- </xsl:for-each>
- </table>
- <xsl:apply-templates select="date" />
- // HTML TABLE STUFF
- <tbody>
- <tr>
- <td><strong>Meter Number</strong></td>
- <td><strong>This Read</strong></td>
- <td><strong>Previous Read</strong></td>
- <td><strong>Usage (kWh)</strong></td>
- </tr>
- <tr>
- <td><xsl:value-of select="@number" /></td>
- <td><xsl:value-of select="reading" /></td>
- <td></td>
- <td><xsl:value-of select="reading" /></td>
- </tr>
- </tbody>
- // HTML TABLE STUFF
- </xsl:for-each>
- </xsl:template>
- <xsl:template match="date">
- <p><strong><u>Account Summary</u></strong> - <xsl:value-of select="." /></p>
- </xsl:template>
- </xsl:stylesheet>