2

I have a function in PHP that retrieves all the directories and files from a given path. This returns me an array like:

array(
    "dirname1" => array(
        "dirname2" => array(
            "dirname3" => array(
                "0" => "file1",
                "1" => "file2",
                "2" => "file3"
            ),
            "0" => "file4",
            "1" => "file5",
            "2" => "file6",
            "dirname4" => array(
                "0" => "file7",
                "1" => "file8"
            )
        ),
        "0" => "file9",
        "1" => "file10"
    ),
    "0" => "file11",
    "1" => "file12",
    "2" => "file13"
);

What I finally need is a multidimensional (don't know if is the exactly word) list with <ul /> and <li /> generated with XSLT 1.0 from a XML file, like:

<ul>
    <li class="dirname">
        dirname1
        <ul>
            <li class="dirname">
                Dirname2
                <ul>
                    <li class="dirname">
                        Dirname3
                        <ul>
                            <li>file1</li>
                            <li>file2</li>
                            <li>file3</li>
                        </ul>
                    </li>
                    <li>file4</li>
                    <li>file5</li>
                    <li>file6</li>
                    <li class="dirname">
                        dirname4
                        <ul>
                            <li>file7</li>
                            <li>file8</li>
                        </ul>
                    </li>
                </ul>
            </li>
            <li>file9</li>
            <li>file10</li>
        </ul>
    </li>
    <li>file11</li>
    <li>file12</li>
    <li>file13</li>
</ul>

And finally, inside every <li /> I need the path in a <a />, like:

<li class="dirname"><a href="/dirname1">dirname1</a></li>

<li><a href="/dirname1/dirname2/dirname3/file1">file1</a></li>

<li><a href="/dirname1/file9">file9</a></li>

Actually I don't have the XML that I need to convert because I don't know what can be a nice structure for then convert it to XSLT 1.0. I have the paths inside the <a />. I can do it with PHP if necessary and I can detect in PHP when it is a directory or when not and we can also add something on the XML to detect the class="dirname".

I hope I've given sufficient information to understand me.

Thank you in advance!

Wayne
  • 59,728
  • 15
  • 131
  • 126
udexter
  • 2,307
  • 10
  • 41
  • 58
  • possible duplicate of [Multidimensional array iteration](http://stackoverflow.com/questions/2207599/multidimensional-array-iteration) – Gordon Apr 19 '11 at 08:44
  • @Gordon: I also need a recursive function in XSLT, is not what they ask on your link. Thank you anyway. :) – udexter Apr 19 '11 at 08:48
  • @Gordon: sorry, English is not my main language. The ul/li output list needs to be generated from an XML file. I added this: *What I finally need is a multidimensional (don't know if is the exactly word) list with
      and
    • **generated with XSLT 1.0 from a XML file*** – udexter Apr 19 '11 at 09:04
  • @udexter why do you have to do it with an XSLT? Why cant you just create the html output from the multidimensional php array? – Gordon Apr 19 '11 at 09:07
  • @udexter: Why not swap multidimensional with recursive in your title? It's probably better to understand? It's just an idea? – Micromega Apr 19 '11 at 09:10
  • @Gordon: because the (private) framework/MVC where I'm developing are using XML for the data output and XSLT for rendering the view. :( – udexter Apr 19 '11 at 09:10
  • @udexter: Very smart I wanted to do same a long time ago. It's not that difficult. Did you checked http://www.w3schools.com/xsl? – Micromega Apr 19 '11 at 09:34
  • @epitaph: Is where i learned :P. I've almost the website done, with the ability to separate footer, headers, sidebars... or like taking, for a multilingual site, the text from a XML lang file. It's very clean, because we've all the data on a XML file and it's easy for human read... but there are things like this that are difficult for a non-advance XML/XSLT programmer. :( – udexter Apr 19 '11 at 09:42