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

Re: Grouping question

Subject: Re: Grouping question
From: M Balaji <msbalaji82@xxxxxxxxx>
Date: Thu, 14 May 2009 14:14:51 +0530
Re:  Grouping question
Hi Martin,

Thanks for the reply :-)

Grouping is working properly. But "h4" is appear the child of "h2".
"h4" is grouped under the frist sibling of "h2". Please refer the
below output, frist "h4" element is surronded by "p" tag.  How do I
solve this?

<root>
   <h2>testing<p>data recovery, and application testing. <h4>Support
for file system<p>Objects for replication:</p>
         </h4>
      </p>
      <h3>Session<p>Before creating sessions... <h5>Wizard<p>In
Manager, you can . </p>
            </h5>
         </p>
      </h3>
      <h3>Wizard<p>In Manager, you can . </p>
         <h4>Support for file system<p>Objects for replication:</p>
         </h4>
      </h3>
   </h2>
   <h2>testing1</h2>
</root>


Thanks in Advance,
Balaji. M

On Wed, May 13, 2009 at 7:25 PM, Martin Honnen <Martin.Honnen@xxxxxx> wrote:
> M Balaji wrote:
>
>> How do I need to write the for-each-group element for the above condition?
>
> Here is an attempt with a function:
>
> <xsl:stylesheet
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>  exclude-result-prefixes="xsd mf"
>  xmlns:mf="http://example.com/2009/mf"
>  version="2.0">
>
>  <xsl:output indent="yes"/>
>
>  <xsl:function name="mf:group-heading" as="element()*">
>    <xsl:param name="els" as="element()*"/>
>    <xsl:param name="level" as="xsd:integer"/>
>    <xsl:for-each-group select="$els" group-starting-with="*[local-name() eq
> concat('h', $level)]">
>      <xsl:element name="{local-name()}">
>        <xsl:apply-templates/>
>        <xsl:sequence select="mf:group-heading(current-group() except .,
> $level + 1)"/>
>      </xsl:element>
>    </xsl:for-each-group>
>  </xsl:function>
>
>  <xsl:template match="root">
>    <xsl:copy>
>      <xsl:sequence select="mf:group-heading(*, 2)"/>
>    </xsl:copy>
>  </xsl:template>
>
> </xsl:stylesheet>
>
> When applied to
>
> <root>
> <h2>testing</h2>
> <p>data recovery, and application testing. </p>
> <h4>Support for file system</h4>
> <p>Objects for replication:</p>
> <h3>Session</h3>
> <p>Before creating sessions... </p>
> <h3>Wizard</h3>
> <p>In Manager, you can . </p>
> <h4>Support for file system</h4>
> <p>Objects for replication:</p>
> <h2>testing1</h2>
> </root>
>
> Saxon 9 gives me
>
> <root>
>   <h2>testing<p>data recovery, and application testing. <h4>Support for
file
> system<p>Objects for replication:</p>
>         </h4>
>      </p>
>      <h3>Session<p>Before creating sessions... </p>
>      </h3>
>      <h3>Wizard<p>In Manager, you can . </p>
>         <h4>Support for file system<p>Objects for replication:</p>
>         </h4>
>      </h3>
>   </h2>
>   <h2>testing1</h2>
> </root>
>
> which I think has the structure you want, you might need to tune the
> whitespace/indentation.
>
>
> --
>
>        Martin Honnen
>        http://msmvps.com/blogs/martin_honnen/

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.