Hi
Please help this is driving me insane, I've simplified my XML and stylesheet below for explaining what I'm trying to achieve.
My stylesheet is successfully generating a HTML file for each of my categories using title i.e.
This Category.html
That Category.html
It also generates a simple index.html at the end which contains links to each of these pages.. However what I also want to achieve is:
This Category - This Sub Category 1.html
This Category - This Sub Category 2.html
This Category - This Sub Category 3.html
That Category - That Sub Category 1.html
That Category - That Sub Category 2.html
That Category - That Sub Category 3.html
With an index page that references each page, once I have this in place I can really start my website for my shop. I'm assuming I need another for-each loop
within the category for-each loop but when I do this I only get the 'This Category.html' level files generated. Whereas if I remove the inner for-each loop
I also get:
'This Sub Category 1 This Sub Category 2 This Sub Category 3.html' etc
Not what I want but hopefully I'm already close.
Hope this makes sense and thanks in advance.
XML:
<?xml version = "1.0" encoding = "UTF-8"?>
<categories>
<category>
<title>This Category</title>
<subcategory>This Sub Category 1</subcategory>
<subcategory>This Sub Category 2</subcategory>
<subcategory>This Sub Category 3</subcategory>
</category>
<category>
<title>That Category</title>
<subcategory>That Sub Category 1</subcategory>
<subcategory>That Sub Category 2</subcategory>
<subcategory>That Sub Category 3</subcategory>
</category>
</categories>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="text"/>
<xsl:output method="html" indent="yes" name="html"/>
<xsl:template match="/">
<xsl:for-each select="categories/category">
<xsl:variable name="varCat">
<xsl:value-of select="title"/>
</xsl:variable>
<xsl:for-each select="categories/category">
<xsl:variable name="varSubCat">
<xsl:value-of select="subcategory"/>
</xsl:variable>
<xsl:variable name="filename"
select="concat('output/',$carCat,' - '$varSubCat,'.html')" />
<xsl:value-of select="$filename" />
<xsl:result-document href="{$filename}" format="html">
<html><body>
<xsl:value-of select="subcategory"/>
</body></html>
</xsl:result-document>
</xsl:for-each>
<xsl:variable name="filename"
select="concat('output/',$varCat,'.html')" />
<xsl:value-of select="$filename" />
<xsl:result-document href="{$filename}" format="html">
<html><body>
<xsl:value-of select="title"/>
</body></html>
</xsl:result-document>
</xsl:for-each>
<xsl:result-document href="output/index.html"
format="html">
<html><head><title>Test Index</title></head>
<body>
<xsl:for-each select="categories/category">
<a href="{title}.html"><xsl:value-of select="title" />
</a><br/>
</xsl:for-each>
</body>
</html>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>