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

grouping problem

Subject: grouping problem
From: M Balaji <msbalaji82@xxxxxxxxx>
Date: Wed, 22 Apr 2009 10:36:17 +0530
 grouping problem
Hi All,

I need to group the input.

Input:

<root>
  <num>This chapter is..:</num>
  <test>A class is a module of Java code:</test>
  <section>or</section>
  <title>Java 5.0</title>
  <test>The Java programming language</test>
  <p>Write Once, Run Anywhere.</p>
  <num>Java j2ee</num>
  <p>Broad Responsibilities:...</p>
  <num>Job Description Perform Oracle...</num>
</root>

Expected output:

<msgs>
  <msg>
     <num>This chapter is..:</num>
     <import>
        <test>A class is a module of Java code:</test>
        <title>Java 5.0</title>
        <section>or</section>
        <test>The Java programming language</test>
     </import>
     <p>Write Once, Run Anywhere.</p>
  </msg>
  <msg>
     <num>Java j2ee</num>
     <p>Broad Responsibilities:...</p>
  </msg>
  <msg>
     <num>Job Description Perform Oracle...</num>
  </msg>
</msgs>


I tried with the below stylesheet.

<xsl:template match="root">
<msgs>
<xsl:for-each-group select="*"
group-starting-with="*[starts-with(name(), 'num')]">
<msg>
<xsl:apply-templates select="." mode="msg"/>
<xsl:for-each-group select="current-group() except ."
group-ending-with="test[last()]">
<xsl:apply-templates select="." mode="msg"/>
<import>
<xsl:apply-templates select="current-group() except ." mode="msg"/>
</import>
</xsl:for-each-group>
</msg>
</xsl:for-each-group>
</msgs>
</xsl:template>

Output received:-

<msgs>
   <msg>
      <num>This chapter is..:</num>
      <import>
         <test>A class is a module of Java code:</test>
         <section>or</section>
         <title>Java 5.0</title>
         <test>The Java programming language</test>
      </import>
      <import><!--Import tag need to remove -->
         <p>Write Once, Run Anywhere.</p>
      </import>
   </msg>
   <msg>
      <num>Java j2ee</num>
      <import> <!-- import tag need to remove -->
         <p>Broad Responsibilities:...</p>
      </import>
   </msg>
   <msg>
      <num>Job Description Perform Oracle...</num>
   </msg>
</msgs>

Where I need to modify the stylesheet to get the expected output?


Thanks in advance,
Balaji. M

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.