Guttyguppy wrote:
> I have
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet version="1.0"
> xmlns
sl="http://www.w3.org/1999/XSL/Transform">
> <xsl:template match="/">
> <html>
> <body>
> <xsl:for-each select="category/entry">
> <xsl:value-of select="job"/><br/>
> <xsl:value-of select="date"/><br/>
> </xsl:for-each>
> </body>
> </html>
> </xsl:template>
> </xsl:stylesheet>
>
> and my .xml file has
>
> <category>Jobs</category>
> <entry>
> <job>Plumber</job>
> <date>12/5/04</date>
> </entry>
> <category>Teams</category>
> <entry>
> <job>Jets</job>
> <date>12/3/04</date>
> </entry>
>
> I want to have unlimited entries, but I also want to run a for-each on
> the categories. How would I structure something like that? I'm
> absolutely new to this, so please bear with me! Thanks.
Nicolas has already suggested a different markup design, which is more
explicit and properly nested. The trick is to enclose things in the
elements which name what they are -- personally I prefer compactness,
especially where the data is categorical:
<data>
<entry cat="Jobs" job="Plumber" date="2004-05-12"/>
<entry cat="Teams" job="Jets" date="2004-03-12
</data>
I STRONGLY recommend using ISO 8601 dates in the format given: they are
much easier to manipulate.
Then you don't need for-each at all:
<xsl:apply-templates select="/data/entry">
<xsl:sort select="@cat"/>
<xsl:sort select="@date"/>
</xsl:apply-templates>
///Peter