title: XQuery expression. Something about ordering
body: <p>I have to order and then print out parts of a text. I've tried some expressions and finally became the code that help me, but I think it isn't really good. </p>
  
  <p>I will post a part of the text and then the code that I've made.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0"?&gt;
  &lt;recipes&gt;
    &lt;recipe&gt;
      &lt;title&gt;Beef Parmesan with Garlic Angel Hair Pasta&lt;/title&gt;
      &lt;ingredient name="beef cube steak" amount="1.5" unit="pound"/&gt;
      &lt;ingredient name="onion, sliced into thin rings" amount="1"/&gt;
      &lt;ingredient name="green bell pepper, sliced in rings" amount="1"/&gt;
      &lt;ingredient name="Italian seasoned bread crumbs" amount="1" unit="cup"/&gt;
      &lt;ingredient name="grated Parmesan cheese" amount="0.5" unit="cup"/&gt;
      &lt;ingredient name="olive oil" amount="2" unit="tablespoon"/&gt;
      &lt;ingredient name="spaghetti sauce" amount="1" unit="jar"/&gt;
      &lt;ingredient name="shredded mozzarella cheese" amount="0.5" unit="cup"/&gt;
      &lt;ingredient name="angel hair pasta" amount="12" unit="ounce"/&gt;
      &lt;ingredient name="minced garlic" amount="2" unit="teaspoon"/&gt;
      &lt;ingredient name="butter" amount="0.25" unit="cup"/&gt;
      &lt;preparation&gt;
        &lt;step&gt;
          Preheat oven to 350 degrees F (175 degrees C).
        &lt;/step&gt;
        &lt;step&gt;
          Cut cube steak into serving size pieces. Coat meat with the bread crumbs
          and parmesan cheese. Heat olive oil in a large frying pan, and saute 1
          teaspoon of the garlic for 3 minutes. Quick fry (brown quickly on both sides)
          meat. Place meat in a casserole baking dish, slightly overlapping edges.
          Place onion rings and peppers on top of meat, and pour marinara sauce
          over all.
        &lt;/step&gt;
        &lt;step&gt;
          Bake at 350 degrees F (175 degrees C) for 30 to 45 minutes, depending on
          the thickness of the meat. Sprinkle mozzarella over meat and leave in the
          oven till bubbly.
        &lt;/step&gt;
        &lt;step&gt;
          Boil pasta al dente. Drain, and toss in butter and 1 teaspoon garlic. For a
          stronger garlic taste, season with garlic powder. Top with grated parmesan
         and parsley for color. Serve meat and sauce atop a mound of pasta!
        &lt;/step&gt;
      &lt;/preparation&gt;
      &lt;comment&gt;
        Make the meat ahead of time, and refrigerate over night, the acid in the
        tomato sauce will tenderize the meat even more. If you do this, save the
        mozzarella till the last minute.
      &lt;/comment&gt;
      &lt;nutrition calories="1167" fat="23" carbohydrates="45" protein="32"/&gt;
    &lt;/recipe&gt;
  &lt;recipe&gt;
      &lt;title&gt;Ricotta Pie&lt;/title&gt; 
      &lt;ingredient name="filling"&gt;
        &lt;ingredient name="ricotta cheese" amount="3" unit="pound"/&gt; 
        &lt;ingredient name="eggs" amount="12"/&gt; 
        &lt;ingredient name="white sugar" amount="2" unit="cup"/&gt; 
        &lt;ingredient name="vanilla extract" amount="2" unit="teaspoon"/&gt; 
        &lt;ingredient name="semisweet chocolate chips" amount="0.25" unit="cup"/&gt; 
        &lt;preparation&gt;
          &lt;step&gt;
            Beat the 12 eggs, 2 cups sugar and vanilla extract together. Stir in
            the ricotta cheese and the chocolate chips. Set aside.
          &lt;/step&gt;
        &lt;/preparation&gt;
      &lt;/ingredient&gt;
      &lt;ingredient name="dough"&gt;
        &lt;ingredient name="flour" amount="4" unit="cup"/&gt; 
        &lt;ingredient name="baking powder" amount="5" unit="teaspoon"/&gt; 
        &lt;ingredient name="white sugar" amount="1" unit="cup"/&gt; 
        &lt;ingredient name="shortening" amount="0.5" unit="cup"/&gt; 
        &lt;ingredient name="eggs, lightly beaten" amount="4"/&gt; 
        &lt;ingredient name="vanilla extract" amount="1" unit="teaspoon"/&gt; 
        &lt;preparation&gt;
          &lt;step&gt;
            Combine the flour, baking powder, and 1 cup of the sugar together. Cut in the
            shortening and mix until the mixture resembles coarse crumbs. Mix in 4 of
            the eggs and 1 teaspoon of the vanilla. Divide dough into 4 balls and chill (if
            needed).
          &lt;/step&gt;
        &lt;/preparation&gt;
      &lt;/ingredient&gt;
      &lt;ingredient name="milk" amount="*"/&gt;
      &lt;preparation&gt;
        &lt;step&gt;
          Preheat oven to 325 degrees F (165 degrees C). Grease two deep dish pie
          plates.
        &lt;/step&gt;
        &lt;step&gt;
          Roll out 2 of the balls to fit into the pie pans. Do not make the crust too thick
          as it will expand during cooking and get too thick. Do not flute the edges of
          the dough. Roll out the other 2 balls of dough and cut each into 8 narrow
          strips for the top of the crust. Alternately you can use cookie cutters and
          place the cutouts on the top of the pies.
        &lt;/step&gt;
        &lt;step&gt;
          Pour the filling evenly into the pie crusts. Top each pie with 8 narrow strips
          of dough or cookie cut-outs. Brush top of pie with milk for shine. Place foil on
          the edge of crust.
        &lt;/step&gt;
        &lt;step&gt;
          Bake at 325 degrees F (165 degrees C) for 20 to 30 minutes then remove
          foil. Continue to bake for another 25 or 30 minutes or until a knife inserted in
          the center comes out clean.
        &lt;/step&gt;
      &lt;/preparation&gt;
      &lt;nutrition calories="349" fat="18" carbohydrates="64" protein="18"/&gt;
    &lt;/recipe&gt;
  &gt; &lt;/recipes&gt;
  </code></pre>
  
  <p>The code I've made is following</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;result&gt;
      {
          for $x in doc()/recipes/recipe
          order by $x/nutrition[@calories&gt;600]
          return 
              ($x/title) |($x/nutrition[@calories])
      }
  &lt;/result&gt;
  </code></pre>
  
  <p>The main idea of XQuery expression is to show the title and the calories ordered by calories in <code>&lt;result&gt;</code> tag. </p>