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>

I use java parser
so that set the parameter
in a batch

java -mx250m -ms250m -cp saxon9he.jar;xercesImpl-2.9.1.jar net.sf.saxon.Transform -x:org.apache.xerces.parsers.SAXParser -o:index.html -s:%1 -xsl:%2

For windos I make a ein.bat

ein store.xml store2.xsl

make a index.html with intern xsl
%1 store.xml
%2 store2.xsl

and many others html create by xsl:result-document href="{$filename}" format="html"

use not for-each

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">


	<xsl:output method="html" indent="yes" name="html"/>

	<xsl:template match="/">
		<html>
			<style type="text/css">table {
		border: solid 3px #000000;
		}
		th,td {
		border: solid 3px #000000;
		}</style>
			<body>
				<table>
				<th>
				Title
				</th>
				<th>
				Sub Category
				</th>
				<th>
				
				</th>
					<xsl:apply-templates select="categories"/>
				</table>
			</body>
		</html>
	</xsl:template>

	<xsl:template match="categories">
		<xsl:apply-templates select="category"/>
	</xsl:template>

	<xsl:template match="category">
		<xsl:apply-templates select="subcategory">
			<xsl:with-param name="title" select="title"/>
		</xsl:apply-templates>
	</xsl:template>
	<xsl:template match="subcategory">
		<xsl:param name="title"/>
		<xsl:variable name="filename" select="concat('output/',$title,' - ',.,'.html')"/>
		<tr>
			<td>
				<xsl:value-of select="$title"/>
			</td>
			<td>
				<xsl:value-of select="concat(.,'.html')"/>
			</td>
			<td>
			<a href="{$filename}">select</a>
			</td>
		</tr>
		<!-- output in html file -->
		<xsl:result-document href="{$filename}" format="html">
			<html>
				<body>
					<xsl:value-of select="."/>
					<a href="../index.html">back</a>
				</body>
			</html>
		</xsl:result-document>
	</xsl:template>
</xsl:stylesheet>

I create a index.html so you can select the create
html code.
in the select html i make a back anker

<html>
  <style type="text/css">table {
		border: solid 3px #000000;
		}
		th,td {
		border: solid 3px #000000;
		}
  </style>
  <body>
    <table>
      <th>
				Title
				
      </th>
      <th>
				Sub Category
				
      </th>
      <th></th>
      <tr>
        <td>This Category</td>
        <td>This Sub Category 1.html</td>
        <td>
          <a href="output/This Category - This Sub Category 1.html">select</a>
        </td>
      </tr>
      <tr>
        <td>This Category</td>
        <td>This Sub Category 2.html</td>
        <td>
          <a href="output/This Category - This Sub Category 2.html">select</a>
        </td>
      </tr>
      <tr>
        <td>This Category</td>
        <td>This Sub Category 3.html</td>
        <td>
          <a href="output/This Category - This Sub Category 3.html">select</a>
        </td>
      </tr>
      <tr>
        <td>That Category</td>
        <td>That Sub Category 1.html</td>
        <td>
          <a href="output/That Category - That Sub Category 1.html">select</a>
        </td>
      </tr>
      <tr>
        <td>That Category</td>
        <td>That Sub Category 2.html</td>
        <td>
          <a href="output/That Category - That Sub Category 2.html">select</a>
        </td>
      </tr>
      <tr>
        <td>That Category</td>
        <td>That Sub Category 3.html</td>
        <td>
          <a href="output/That Category - That Sub Category 3.html">select</a>
        </td>
      </tr>
    </table>
  </body>
</html>

one of html create

<html>
   <body>This Sub Category 1<a href="../index.html">back</a></body>
</html>

Many thanks for the response I'm currently working through the code to make sense of it all as I like to understand what it's doing, although good news is I have literally been able to copy the stylesheet code you have provided and immediately generate the html pages I require.

What I have yet to understand is what is the purpose of the code setting the table properties (i.e. border size etc) no tables are displayed in the html pages?

Also the index.html page is not automatically generated with links to each page, should it be? Once I have that I'm quietly confident of working on improving the quality of the page.

Lastly, I need to pull the products I am selling from my products.xml file (short example below) do I do this within the </xsl:result-document> section?

Thanks in advance, a friend advised I use XML for my website and I see the benefits long term but I have a lot to learn still I guess!

<?xml version = "1.0" encoding = "UTF-8"?>

<catalog>
<product>
<productid>0001</productid>
<title>Product 1</title>
<price>2.99</price>
<image>prod1.jpg</image>
<imagelarge>prod1x.jpg</imagelarge>
<desc>A description of product 1.</desc>
<features>Prod1 feature</features>
<features>Prod1 another feature</features>
<stock>In Stock</stock>
<include>
<category>This Category</category>
<subcategory>This Subcategory 1</subcategory>
</include>
<include>
<category>This Category</category>
<subcategory>This Subcategory 4</subcategory>
</include>
</product>
<product>
<productid>0002</productid>
<title>Product 2</title>
<price>1.99</price>
<image>prod2.jpg</image>
<imagelarge>prod2x.jpg</imagelarge>
<desc>A description of product 2.</desc>
<features>Prod2 only one feature</features>
<stock>Out of Stock</stock>
<include>
<category>That Category</category>
<subcategory>That Subcategory 3</subcategory>
</include>
</product>
</catalog>

I have successfully produced schemas, hooray! Basically a product:

Must have a 'ProductID', 'Title', 'Price', 'Image', 'Desc', 'Stock' and at least one 'Include'

It may not have 'ImageLarge'

It may not have 'Features' but can have several

It may have more than one 'Include' to show in multiple Categories

can explain more what you wanted
you use only Browser ??

call me via icq see in profil

Apologies if I have confused the situation and also for the code displaying as it is I did insert the tags but clearly did something wrong.

Your advice on the stylesheet has worked perfectly, the only advice I now would be grateful for is generating the index.html which just contains links to each page, I can then work on design at a later date.

Lastly, some direction on how you then reference another xml file to extract details during page creation would be much appreciated. These will be my products as the example of code above.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.