Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Different behaviour for the first item in a for-each-group

From: "Mark Wilson" <mark@--------.--->
To: <xsl-list@-----.------------.--->
Date: 10/31/2009 10:52:00 PM
Hi Ken,
I was not careful in the way I described this problem. Each group consists 
of a single title with one or more citations. What I must have said is that 
I wanted to set the Title in each group to "keep". What I *should* have said 
was, I want to set the only the first group to "keep". For the input data at 
the end of this email, that would be the title "Further observations". All 
the rest would not be marked "keep".

Clearly, I do not want (from listing 1):
                    <xsl:if test="position()=1">
                        <xsl:attribute 
name="keep-with-previous">always</xsl:attribute>
                    </xsl:if>
However, I do not know XPath well. How do I select only the first group for 
marking and let the other groups pass without marking them?

All help appreciated.
Mark

Listing 1:
<xsl:template name="format-article">
        <xsl:for-each-group select="../Article" group-by="Title">
            <xsl:sort select="Title"/>
            <xsl:sort select="Year"/>
            <xsl:sort select="IssueNumber" data-type="number"/>
            <xsl:sort select="Page"/>
            <xsl:for-each select="current-group()">
                <fo:table-row>
                    <!-- Put the first group in a keeping row-->
                    <xsl:if test="position()=1">
                        <xsl:attribute 
name="keep-with-previous">always</xsl:attribute>
                    </xsl:if>
                    <!-- And all the other groups in a non-"keeping" row -->
                    <fo:table-cell>
                        <fo:block>
                            <xsl:choose>
                                <xsl:when test="parent::Item">
                                    <xsl:call-template name="article0"/>
                                </xsl:when>
                                <xsl:when test="parent::Level1">
                                    <xsl:call-template name="article1"/>
                                </xsl:when>
                                <xsl:when test="parent::Level2">
                                    <xsl:call-template name="article2"/>
                                </xsl:when>
                                <xsl:when test="parent::Level3">
                                    <xsl:call-template name="article3"/>
                                </xsl:when>
                            </xsl:choose>
                            <fo:block xsl:use-attribute-sets="citation">
                                <fo:wrapper xsl:use-attribute-sets="title">
                                    <!--for a given title-->
                                    <xsl:apply-templates select="Title"/>
                                </fo:wrapper>
                                <xsl:apply-templates select="Person"/>
                                <!--and for each citation-->
                                <xsl:apply-templates 
select="current-group()" mode="format"/>
                            </fo:block>
                        </fo:block>
                    </fo:table-cell>
                </fo:table-row>
            </xsl:for-each>
        </xsl:for-each-group>
    </xsl:template>

Input data:
<Item>
     <Article>
        <Title>Further observations</Title>
        <IssueName>Mar/Apr</IssueName>
        <Year>1999</Year>
        <Page>34</Page>
        <IssueNumber>2</IssueNumber>
    </Article>
    <Article>
        <Title>Letters to the editor</Title>
        <IssueName>Nov/Dec</IssueName>
        <Year>2001</Year>
        <Page>27</Page>
        <IssueNumber>6</IssueNumber>
    </Article>
    <Article>
        <Title>Philatelic news and views</Title>
        <IssueName>Sep/Oct</IssueName>
        <Year>2001</Year>
        <Page>35</Page>
        <IssueNumber>5</IssueNumber>
    </Article>
    <Article>
        <Title>Philatelic news and views</Title>
        <IssueName>Sep/Oct</IssueName>
        <Year>2002</Year>
        <Page>11</Page>
        <IssueNumber>5</IssueNumber>
    </Article>
    <Article>
        <Title>Philatelic news and views</Title>
        <IssueName>Nov/Dec</IssueName>
        <Year>2002</Year>
        <Page>28</Page>
        <IssueNumber>6</IssueNumber>
    </Article>
    <Article>
        <Title>Philatelic news and views</Title>
        <IssueName>Jan/Feb</IssueName>
        <Year>2003</Year>
        <Page>24</Page>
        <IssueNumber>1</IssueNumber>
    </Article>
    <Article>
        <Title>Philatelic news and views</Title>
        <IssueName>Nov/Dec</IssueName>
        <Year>2006</Year>
        <Page>18</Page>
        <IssueNumber>6</IssueNumber>
    </Article>
</Item> 



--~------------------------------------------------------------------
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@l...>
--~--



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent