Patrick schrieb:
Hello All,
I am new to xml and trying to make it work. I'm having a bit of trouble
with for-each loops.
Hi Patrick,
although your problem isn't quit clear. The nested for-each loops are
always a hazard. Simply dont use them ....
use templates on your tree. A bit more wordy - but a lot more flexible
and editable
message continued after the code
----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output omit-xml-declaration="yes" method="xml" />
<xsl:template match="/">
<!-- stuff for the html output -->
<xsl:element name="html">
<xsl:element name="head">
<xsl:element name="title">
xsl w/o for-each
</xsl:element>
</xsl:element>
<xsl:element name="body">
<xsl:apply-templates />
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="met_packages">
<!-- the met packages make a table -->
<xsl:element name="table">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="weatherpak">
<!-- first theHeader -->
<xsl:element name="tr">
<xsl:element name="th">
<xsl:attribute name="align">left</xsl:attribute>
WeatherPak
</xsl:element>
<xsl:element name="th">
<xsl:attribute name="colspan">4</xsl:attribute>
<xsl:value-of select="serial_number" />
</xsl:element>
<xsl:element name="tr">
<xsl:attribute name="bgcolor">#9acd32</xsl:attribute>
<th align="left">Sensor</th>
<th align="left">Sensor Type</th>
<th align="left">Range</th>
<th align="left">Accuracy</th>
<th align="left">Resolution</th>
</xsl:element>
<xsl:apply-templates select="sensors"/>
</xsl:element>
</xsl:template>
<xsl:template match="sensors">
<xsl:element name="tr">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="sensors/*">
<xsl:element name="td">
<xsl:value-of select="." />
</xsl:element>
</xsl:template>
<xsl:template match="*|@*" />
</xsl:stylesheet>
----------------------------------------
this is a bit mor flexible eg. you want to highlight the resolution just
add:
<xsl:template match="sensors/resolution">
<xsl:element name="td">
<b><xsl:value-of select="." /></b>
</xsl:element>
</xsl:template>
HIH
Jo
just add:
<xsl:template match