0

I'm new to PHP but quite used to other languages. I'm trying to make a list of recipe titles that are fetched from several XML files, if they match a specific recipe category.

I have written a PHP function that loops through all the XML-recipes on my server and checks for the category. This works fine when I call it with a dummy-category that is hardcoded!

<?php
getSimilar($category){
    $list = array();
    foreach(glob("*xml") as $filename) {
        $xml = simplexml_load_file($filename);
        $result = $xml->xpath("//categories/cat");
        if($result[0] == $category) {
            $titel = $xml->xpath("//title");
            array_push($list, $titel[0]);
            echo "<option value=\"recept\">" . $titel[0] . "</option>";
        }
    }
}
?>

I want the result to be put into <option>-tags to be displayed as XSLT / HTML. I'm trying to call it this way, but it isn't working for me!

<xsl:variable name="catParam" select="recipeml/recipe/head/categories/cat"/>

<div class="recipeDetails">
        <h2>Recipes similar to <xsl:value-of select="recipeml/recipe/head/title"/></h2>
        <p>These are just examples of dishes closely related to <xsl:value-of select="recipeml/recipe/head/title"/>.</p>
        <form>
            <select>
                <?php
                 include ('createSimilarList.php');
                 getSimilar($catParam);
                 ?>
                <?php getSimilar($catParam);?>
            </select>
        </form>
</div>

I want to make it as simple as possible, since I previously have very little experience of neither XSLT or PHP.

Any ideas on how I can do this are welcome! Thanks!

Daniel B
  • 8,770
  • 5
  • 43
  • 76

0 Answers0