2012-04-26 2 views
1

XML 파일이 있습니다. 각 레서피는 요소를 사용하여 정의됩니다. My XSL <xsl:for-each select="//recipe">을 사용하여 표를 채 웁니다. 유일한 문제는 내가 원하는 결과를 얻지 못한다는 것입니다. for-each 이외의 모든 것은 훌륭하게 작동하지만 for-each 내의 모든 것이 전혀 나타나지 않습니다.XML과 XSL이 원하는 결과를 얻지 못했습니다.

내 XSL에서 오류가 표시되지 않지만 다시 작성하는 데는 최선이 아닙니다. 어떤 도움을 주시면 감사하겠습니다.

출력 :

Testing HTML 
Testing Body 
Testing Table 

XML

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="recipe.xsl"?> 
<recipesXML xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com recipe.xsd "> 
    <recipe> 
     <name> Burnt Cookies </name> 
     <image>images/burntcookie.jpg</image> 
     <prepTime> 120 min </prepTime> 
     <cookTime> 300 min </cookTime> 
     <ingredients>Animal Crackers</ingredients> 
     <instructions> 
      <step num="1">Place Animal Crackers on a pan</step> 
      <step num="2">Place Pan in Oven</step> 
      <step num="3"> ... </step> 
      <step num="4">Profit</step> 
     </instructions> 
    </recipe> 
    <recipe> 
     <name>Delicious Black Bean Burritos</name> 
     <image>images/</image> 
     <prepTime>10 min</prepTime> 
     <cookTime>15 min</cookTime> 
     <ingredients>2 (10 inch) flour tortillas</ingredients> 
     <ingredients>2 tablespoons vegetable oil</ingredients> 
     <ingredients>1 small onion, chopped</ingredients> 
     <ingredients>1/2 red bell pepper, chopped</ingredients> 
     <ingredients>1 teaspoon minced garlic</ingredients> 
     <ingredients>1 (15 ounce) can black beans, rinsed and drained</ingredients> 
     <ingredients>1 teaspoon minced jalapeno peppers</ingredients> 
     <ingredients>3 ounces cream cheese</ingredients> 
     <ingredients>1/2 teaspoon salt</ingredients> 
     <ingredients>2 tablespoons chopped fresh cilantro</ingredients> 
     <instructions> 
      <step num="1">Wrap tortillas in foil and place in oven heated to 350 degrees F (175 degrees C). Bake for 15 minutes or until heated through.</step> 
      <step num="2">Heat oil in a 10-inch skillet over medium heat. Place onion, bell pepper, garlic and jalapenos in skillet, cook for 2 minutes stirring occasionally. Pour beans into skillet, cook 3 minutes stirring.</step> 
      <step num="3">Cut cream cheese into cubes and add to skillet with salt. Cook for 2 minutes stirring occasionally. Stir cilantro into mixture.</step> 
      <step num="4">Spoon mixture evenly down center of warmed tortilla and roll tortillas up. Serve immediately.</step> 
     </instructions> 
    </recipe> 
    <recipe> 
     <name>Cream of Asparagus Soup</name> 
     <image>images/aspSoup.jpg</image> 
     <prepTime>30 min</prepTime> 
     <cookTime>30 min</cookTime> 
     <ingredients>1/4 cup margarine</ingredients> 
     <ingredients>1 onion, chopped</ingredients> 
     <ingredients>3 stalks celery, chopped</ingredients> 
     <ingredients>3 tablespoons all-purpose flour</ingredients> 
     <ingredients>4 cups water</ingredients> 
     <ingredients>1 (10.5 ounce) can condensed chicken broth</ingredients> 
     <ingredients>4 tablespoons chicken bouillon powder</ingredients> 
     <ingredients>1 potato, peeled and diced</ingredients> 
     <ingredients>1 pound fresh asparagus, trimmed and coarsely chopped</ingredients> 
     <ingredients>3/4 cup half-and-half</ingredients> 
     <ingredients>1 tablespoon soy sauce</ingredients> 
     <ingredients>1/4 teaspoon ground black pepper</ingredients> 
     <ingredients>1/4 teaspoon ground white pepper</ingredients> 
     <instructions> 
      <step num="1">Melt butter or margarine in a heavy cooking pot. Add onions and chopped celery; saute until tender, about 4 minutes. Stir in flour, mixing well. Cook for about 1 minute, stirring constantly. Do not burn, or let it go lumpy. Add water, chicken broth, and chicken soup base; stir until smooth. Bring to a boil. Add diced potatoes and chopped asparagus. Reduce heat, and simmer for about 20 minutes.</step> 
      <step num="2">Puree soup in a food processor or blender in batches. Return to pot.</step> 
      <step num="3">Stir in half and half cream, soy sauce, and black and white pepper. Bring soup just to boil. Adjust seasonings to taste. Serve hot.</step> 
     </instructions> 
    </recipe> 
    <recipe> 
     <name>Carrot Cake IV</name> 
     <image>images/carrotcake.jpg</image> 
     <prepTime>30 min</prepTime> 
     <cookTime>30 min</cookTime> 
     <ingredients>1 (18.5 ounce) package carrot cake mix</ingredients> 
     <ingredients>1/2 cup water</ingredients> 
     <ingredients>1/2 cup vegetable oil</ingredients> 
     <ingredients>3 eggs</ingredients> 
     <ingredients>1/2 cup finely chopped walnuts</ingredients> 
     <ingredients>1 (8 ounce) can crushed pineapple with juice</ingredients> 
     <instructions> 
      <step num="1">Preheat oven to 350 degrees F (175 degrees C). Grease and flour two 8 inch round pans.</step> 
      <step num="2">In large bowl, blend cake mix, oil, water, undrained pineapple, eggs, and nuts. Beat for 2 minutes with an electric mixer at medium speed. Spread batter into prepared pans.</step> 
      <step num="3">Bake for 35 to 40 minutes, or until a toothpick inserted in the center comes out clean. Cool. Frost with cream cheese frosting.</step> 
     </instructions> 
    </recipe> 
    <recipe> 
     <name>Eggy Veggie Bake</name> 
     <image>images/eggveggie.jpg</image> 
     <prepTime>10 min</prepTime> 
     <cookTime>35 min</cookTime> 
     <ingredients>1 tablespoon olive oil</ingredients> 
     <ingredients>1 cup sliced halved zucchini</ingredients> 
     <ingredients>3 green onions, chopped</ingredients> 
     <ingredients>1/2 sweet onion, thinly sliced</ingredients> 
     <ingredients>2 roma (plum) tomatoes, chopped</ingredients> 
     <ingredients>1/2 cup chopped fresh mushrooms</ingredients> 
     <ingredients>3 cups chopped baby spinach</ingredients> 
     <ingredients>1/2 lemon, juiced</ingredients> 
     <ingredients>Worcestershire sauce to taste</ingredients> 
     <ingredients>hot sauce to taste</ingredients> 
     <ingredients>garlic powder to taste</ingredients> 
     <ingredients>salt and ground black pepper to taste</ingredients> 
     <ingredients>1 1/2 cups liquid egg substitute</ingredients> 
     <ingredients>1/4 cup shredded Cheddar cheese</ingredients> 
     <instructions> 
      <step num="1">Preheat oven to 350 degrees F (175 degrees C). Spray an 8x8 inch baking dish with cooking spray.</step> 
      <step num="2">Heat the olive oil in a skillet over medium-high heat. Place zucchini, green onions, onion, tomatoes, mushrooms, and spinach in the skillet. Sprinkle with lemon juice, Worcestershire sauce, and hot sauce. Season with garlic powder, salt, and pepper. Cook until tender. Transfer to the prepared baking dish. Pour egg substitute over the vegetables in the dish. Top with cheese.</step> 
      <step num="3">Bake 20 minutes in the preheated oven, or until egg substitute is set and cheese is melted. Cut with a spatula and enjoy!</step> 
     </instructions> 
    </recipe> 
    <recipe> 
     <name>Chicken and Bacon Shish Kabobs</name> 
     <image>images/ChickenBaconShish.jpg</image> 
     <prepTime>25 min</prepTime> 
     <cookTime>20 min</cookTime> 
     <ingredients>1/4 cup soy sauce</ingredients> 
     <ingredients>1/4 cup cider vinegar</ingredients> 
     <ingredients>2 tablespoons honey</ingredients> 
     <ingredients>2 tablespoons canola oil</ingredients> 
     <ingredients>10 large mushrooms, cut in half</ingredients> 
     <ingredients>2 green onions, minced</ingredients> 
     <ingredients>3 skinless, boneless chicken breast halves - cut into chunks</ingredients> 
     <ingredients>1/2 pound sliced thick cut bacon, cut in half</ingredients> 
     <ingredients>1 (8 ounce) can pineapple chunks, drained</ingredients> 
     <ingredients>skewers</ingredients> 
     <instructions> 
      <step num="1">In a large bowl, mix the soy sauce, cider vinegar, honey, canola oil, and green onions. Place the mushrooms and chicken into the mixture, and stir to coat. Cover, and marinate in the refrigerator at least 1 hour.</step> 
      <step num="2">Preheat grill for high heat.</step> 
      <step num="3">Remove the mushrooms and chicken from the marinade and shake off excess. Pour the marinade into a small saucepan and bring to a boil over high heat. Reduce heat to medium-low and simmer for 10 minutes; set aside.</step> 
      <step num="4">Wrap the chicken chunks with bacon, and thread onto skewers so that the bacon is secured. Alternate with mushroom halves and pineapple chunks.</step> 
      <step num="5">Lightly oil the grill grate. Arrange skewers on the prepared grill. Cook 15 to 20 minutes, brushing occasionally with remaining soy sauce mixture, until bacon is crisp and chicken juices run clear.</step> 
     </instructions> 
    </recipe> 
    <recipe> 
     <name>Amish Bread</name> 
     <image>images/amishbread.jpg</image> 
     <prepTime>5 min</prepTime> 
     <cookTime>180 min</cookTime> 
     <ingredients>2 3/4 cups bread flour</ingredients> 
     <ingredients>1/4 cup canola oil</ingredients> 
     <ingredients>1 teaspoon active dry yeast</ingredients> 
     <ingredients>1/4 cup white sugar</ingredients> 
     <ingredients>1/2 teaspoon salt</ingredients> 
     <ingredients>18 tablespoons warm water</ingredients> 
     <instructions> 
      <step num="1">Place ingredients in the pan of the bread machine in the order recommended by the manufacturer. Select White Bread cycle; press Start.</step> 
      <step num="2">When the dough has raised once and second cycle of kneading begins, turn machine off. Reset by pressing Start once again. This gives the dough two full raising cycles before the final raising cycle prior to baking.</step> 
     </instructions> 
    </recipe> 
    <recipe> 
     <name>Pizza Crust Fantastico</name> 
     <image>images/pizzaCrustFantastico.jpg</image> 
     <prepTime>20 min</prepTime> 
     <cookTime>15 min</cookTime> 
     <ingredients>1 1/2 cups warm water (110 degrees F/45 degrees C)</ingredients> 
     <ingredients>1 tablespoon honey</ingredients> 
     <ingredients>1 3/4 teaspoons active dry yeast</ingredients> 
     <ingredients>2 1/2 cups all-purpose flour</ingredients> 
     <ingredients>3/4 cup whole wheat flour</ingredients> 
     <ingredients>1/4 cup corn flour</ingredients> 
     <ingredients>1 teaspoon salt</ingredients> 
     <ingredients>1 teaspoon ground black pepper</ingredients> 
     <ingredients>1 teaspoon dried oregano</ingredients> 
     <ingredients>1 teaspoon dried basil leaves</ingredients> 
     <ingredients>1 teaspoon dried rosemary, chopped</ingredients> 
     <ingredients>1/2 cup tomato sauce</ingredients> 
     <ingredients>2 tablespoons olive oil</ingredients> 
     <instructions> 
      <step num="1">Pour warm water into a small bowl. Dissolve honey and yeast in water. Let stand until creamy, about 10 minutes.</step> 
      <step num="2">In a large bowl, combine the all-purpose flour, whole wheat flour, corn flour, salt, black pepper, oregano, basil and rosemary. Add the yeast mixture, tomato sauce and olive oil; stir well to combine.</step> 
      <step num="3">When the dough has pulled together, turn it out onto a lightly floured surface and knead until smooth and elastic, about 8 minutes. Lightly oil a large bowl, place the dough in the bowl and turn to coat with oil. Cover with a damp cloth and let rise in a warm place until doubled in volume, about 1 hour. Meanwhile, preheat oven to 450 degrees F (230 degrees C) place pizza stone in oven if one is to be used.</step> 
      <step num="4">Deflate the dough and turn it out onto a lightly floured surface. Divide the dough into two equal pieces and form into rounds, cover and let rest for 10 minutes.</step> 
      <step num="5">Roll the rounds out to crust size. Spread crusts with desired pizza sauce from the center outward and cover with desired toppings. Bake on preheated pizza stone or on lightly oiled pizza pans until cheese is bubbly and golden, about 12 minutes</step> 
     </instructions> 
    </recipe> 
</recipesXML> 

XSL

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"> 
     <html> 
      Testing HTML 
      <body> 
       Testing Body 
       <table border="1"> 
       Testing Table 
        <xsl:for-each select="//recipe"> 
         Testing Each Recipe 
         <tr> 
          <td> 
           Test 
           <xsl:element name="img"> 
            <xsl:attribute name="src"><xsl:value-of select="image"/></xsl:attribute> 
            <xsl:attribute name="alt">recipe</xsl:attribute> 
           </xsl:element> 
          </td> 
          <td> 
           <xsl:value-of select="name"></xsl:value-of> 
          </td> 
         </tr> 
        </xsl:for-each> 
       </table> 
      </body> 
     </html> 
    </xsl:template> 
</xsl:stylesheet> 

답변

4

이 때문에 XML의 기본 네임 스페이스 xmlns="http://www.w3schools.com"이다. 당신이 할 수있는

:

  1. 는 XML에서 제거합니다.

  2. 접두어가있는 네임 스페이스를 추가하고 선택 항목에 접두어를 사용하십시오. (select="//x:recipe")

  3. XSLT 2.0을 사용하는 경우 선택 항목의 접두사로 *을 사용하십시오. (select="//*:recipe")

  4. 선택에서 local-name()을 사용하십시오. 그런데 (select="//*[local-name() = 'recipe']")

+0

사용하여 작성 될 수있다. 그리고 이것이 내가 보통 메모장에서 XML을 프로그래밍하는 이유입니다. ++. 고마워, 나는 그것을 쉽게 제거했다. – meriley

+0

@meriley - 대단히 환영합니다. XML 편집기로 oXygen을 사용합니다. 독립형 플러그인과 Eclipse 플러그인으로 모두 사용할 수 있습니다. 시도 해봐. 나는 당신이 메모장보다 훨씬 더 좋아할 것이라고 확신합니다. ++ :-) –

1

, 즉 IMG 요소는 이클립스가 나타나는 날 과거를 몰래

<img src="{image}" alt="recipe"/> 
관련 문제