Thanks for the response, I needed to maintain the text file in its format and managed to achieve this and a count of lines with:

array = []

file = open('filename.txt')
for line in file.readlines():
line = line.split(',')

i = len(line)


tombliboo Newbie Poster

Hi python fans, hope someone can help me with this.

I have a text file the result of another program which looks like:


This may vary in size but will always be square i.e. 5x5, 9x9 etc so the code needs to accomodate this, the maximum ever size will probably be 12x12.

I want python code which will read in the text file and store it in a way I may then access each individual number.

Thanks in advance, assistance appreciated in the meantime I'm off to try and crack it and if I find out first then I'll post back.

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.

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"?>

0001 Product 1 2.99 prod1.jpg prod1x.jpg A description of product 1. Prod1 feature Prod1 another feature In Stock This Category This Subcategory 1 This Category This Subcategory 4 0002 Product 2 1.99 prod2.jpg prod2x.jpg A description of product 2. Prod2 only one feature Out of Stock That Category That Subcategory 3


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

Must have a ...

tombliboo Newbie Poster


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 version = "1.0" encoding = "UTF-8"?>
        <title>This Category</title>
        <subcategory>This Sub Category 1</subcategory>
        <subcategory>This Sub Category 2</subcategory>
        <subcategory>This Sub Category 3</subcategory>
        <title>That Category</title>
        <subcategory>That Sub Category 1</subcategory>
        <subcategory>That Sub Category 2</subcategory>
        <subcategory>That Sub Category 3</subcategory>


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

<xsl:output method="text"/> ...