[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How to sort sibling elements based on attribute of chi

Subject: How to sort sibling elements based on attribute of child element
From: Philip Steiner <redveedub@xxxxxxxxx>
Date: Tue, 7 Jul 2009 12:49:58 -0700
 How to sort sibling elements based on attribute of chi
Wendell,

Thanks for the solution. The key concept that I learned was how to
select and output the preceding and following siblings of
<Annotation>.

I omitted a key bit of information in my example: <Root> should have
been named <Parent>, since the parent element of Annotation is not the
document root element:

<Root>
   <Junk>junk</Junk>
   <Parent>
       <Stuff>stuff</Stuff>
       <Annotation>
           <Comment Priority="1">my first comment</Comment>
       </Annotation>
       <Annotation>
           <Comment Priority="3">my third comment</Comment>
       </Annotation>
       <Annotation>
           <Comment Priority="2">my second comment</Comment>
       </Annotation>
       <Bother>bother</Bother>
   </Parent>
</Root>

As a consequence, I didn't to use this template to produce output when
there is no Annotation:

<xsl:template match="/*[not(Annotation)]" priority="2">
 <xsl:apply-templates/>
</xsl:template>

Instead, I put a test for <Annotation> into the template - which might
not be the most elegant solution, but it works:

   <xsl:template select="Parent">
       <xsl:choose>
           <xsl:when test="Annotation">
               <xsl:apply-templates
select="Annotation[1]/preceding-sibling::*"/>
               <xsl:apply-templates select="Annotation">
                   <xsl:sort select="*/@Priority"/>
               </xsl:apply-templates>
               <xsl:apply-templates
select="Annotation[last()]/following-sibling::*"/>
           </xsl:when>
           <xsl:otherwise>
               <xsl:apply-templates select="*"/>
           </xsl:otherwise>
       </xsl:choose>
   </xsl:template>

Thanks again for your help!

--
Philip

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.