Hai,
I am having the input like below:
<articles>
<row>
<col>627</col>
<col>Abstracts of the Series of Fascia Congress - Part 4</col>
<col>270</col>
</row>
<row>
<col>661</col>
<col>Abstracts of the Series of Fascia Congress - Part 4</col>
<col>270</col>
</row>
<row>
<col>676</col>
<col>Abstracts of the Series of Fascia Congress - Part 4</col>
<col>271</col>
</row>
<row>
<col>719</col>
<col>Abstracts of the Series of Fascia Congress - Part 4</col>
<col>272</col>
</row>
<row>
<col>706</col>
<col>Prevention & Rehabilitation|Editorial</col>
<col>276</col>
</row>
<row>
<col>690</col>
<col>Prevention & Rehabilitation|Editorial</col>
<col>283</col>
</row>
<row>
<col>721</col>
<col>Prevention & Rehabilitation|Learning Methodology</col>
<col>291</col>
</row>
</articles>
My expected output is as follows:
<sections>
<section-title>Contents</section-title>
<section>
<section-head>Abstracts of the Series of Fascia
Congress - Part
4</section-head>
<para>
<page>270</page>
</para>
<para>
<page>271</page>
</para>
<para>
<page>271</page>
</para>
<para>
<page>272</page>
</para>
</section>
<section>
<section-head>Prevention &
Rehabilitation</section-head>
<section-subhead>Editorial</section-subhead>
<para>
<page>273</page>
</para>
<para>
<page>277</page>
</para>
</section>
<section>
<section-subhead>Learning
Methodology</section-subhead>
<para>
<page>284</page>
</para>
</section>
</sections>
My code is as follows:
<xsl:template match="articles">
<sections>
<section-title>Contents</section-title>
<xsl:for-each-group select="row"
group-by="col[2]">
<xsl:variable name="head"
select="substring-before(current-grouping-key(),'|')"/>
<section>
<xsl:choose>
<xsl:when
test="contains(current-grouping-key(),'|')">
<xsl:for-each-group select="current-group()"
group-by="substring-after(current-grouping-key(),'|')">
<xsl:if
test="position()=1">
<section-head>
<xsl:value-of select="$head"/>
</section-head>
</xsl:if>
<section-subhead>
<xsl:value-of select="current-grouping-key()"/>
</section-subhead>
<xsl:apply-templates select="current-group()"/>
</xsl:for-each-group>
</xsl:when>
<xsl:otherwise>
<section-head>
<xsl:value-of select="current-grouping-key()"/>
</section-head>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</section>
</xsl:for-each-group>
</sections>
</xsl:template>
The output of this code is as follows:
<sections>
<section>
<section-head>Abstracts of the Series of Fascia
Congress - Part
4</section-head>
<para>
<page>270</page>
</para>
<para>
<page>270</page>
</para>
<para>
<page>271</page>
</para>
<para>
<page>272</page>
</para>
</section>
<section>
<section-head>Prevention &
Rehabilitation</section-head>
<section-subhead>Editorial</section-subhead>
<para>
<page>276</page>
</para>
<para>
<page>283</page>
</para>
</section>
<section>
<section-head>Prevention &
Rehabilitation</section-head>
<section-subhead>Learning
Methodology</section-subhead>
<para>
<page>291</page>
</para>
</section>
</sections>
Problem:
<section-head> should come only in the first group and should not come
in the second group. When I use position() in outer group I am getting
the correct value of the position but when I use position() in
nested/inner group the value is always 1. How to achieve the correct
position value in the nested/inner group.
Regards,
Ganesh
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--