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!

4
  • 1
    Where does $catParam come from? Commented Feb 18, 2013 at 21:08
  • The <xsl:variable name="catParam" sel.../> defines it as a variable. I might have gotten the syntax wrong though? Commented Feb 18, 2013 at 21:09
  • 1
    How does PHP know your xslt variables? Commented Feb 18, 2013 at 21:18
  • Thank you Dave for the insightful words! I will look into it and perhaps get in touch with you! =) Commented Feb 19, 2013 at 14:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.