Re: [xsl] Using for-each w/ page-sequence results in "NC105 ID already exists in this document" error

Subject: Re: [xsl] Using for-each w/ page-sequence results in "NC105 ID already exists in this document" error
From: Sharon_Harris@xxxxxxxxxxxxxxxxxxxx
Date: Thu, 20 Sep 2007 09:56:29 -0400
Thank you so much for replying.

>Those should be ref-id= attributes and not id= attributes.  Check
>your XSL-FO instance to make sure <page-number-citation> is using ref-id=.

Yes, I am using ref-id.

Before trying the for-each, I had all the page sequences contained within a
template. I had 6 page sequences within that template that applied to 5
different elements (cover, disclaimer, toc, introduction, lessons,
evaluation). There are multiple instances of the Lesson element but the
Lesson page sequence did not start over for each instance, which is why I
tried using a for-each. I had the page sequences contained within the
following template.
<xsl:template match="/">
      <fo:root>
                  cover page sequence 1
                  disclaimer page sequence 2
                  toc page sequence 3
                  introduction page sequence 4
                  lessons page sequence 5 (contains <apply-templates
select="//Lesson" mode="Activity"/ in the Body flow>
                  evaluation page sequence 6
      </fo:root>
</xsl:template>

Here is the code I used for the page sequences without the for-each.
<xsl:template match="/">
            <fo:root>
                  <xsl:copy-of select="$fo:layout-master-set"/>
                  <fo:page-sequence master-reference="Cover">
                        <fo:flow flow-name="Body">
                              <fo:table table-layout="fixed" width="100%">
                                    <fo:table-column/>
                                    <fo:table-column/>
                                    <fo:table-body>
                                          <fo:table-row>
                                                <fo:table-cell
number-columns-spanned="2">
                                                      <xsl:for-each select
="//FrontMatter/TitlePage/Header">
                                                            <
xsl:apply-templates/>
                                                      </xsl:for-each>
                                                </fo:table-cell>
                                          </fo:table-row>
                                          <fo:table-row>
                                                <fo:table-cell height="
515pt" number-columns-spanned="2">
                                                      <fo:block
xsl:use-attribute-sets="CourseNumber">
                                                            <xsl:value-of
select="//SMCourseNumber"/>
                                                      </fo:block>
                                                      <fo:block
xsl:use-attribute-sets="Title">
                                                            <xsl:for-each
select="//TitlePage">
                                                                  <
xsl:value-of select="//Title"/>
                                                            </xsl:for-each>
                                                      </fo:block>
                                                </fo:table-cell>
                                          </fo:table-row>
                                          <fo:table-row>
                                                <fo:table-cell
xsl:use-attribute-sets="TableCellCenter">
                                                      <fo:block
xsl:use-attribute-sets="SMId">
                                                            <xsl:value-of
select="//FrontMatter/TitlePage/Footer/SMId"/>
                                                      </fo:block>
                                                </fo:table-cell>
                                                <fo:table-cell>
                                                      <fo:block>
                                                            <xsl:for-each
select="//FrontMatter/TitlePage/Footer/FooterImageTitlePage">
                                                                  <
xsl:apply-templates/>
                                                            </xsl:for-each>
                                                      </fo:block>
                                                </fo:table-cell>
                                          </fo:table-row>
                                    </fo:table-body>
                              </fo:table>
                        </fo:flow>
                  </fo:page-sequence>
                  <fo:page-sequence master-reference="default">
                        <fo:flow flow-name="Body">
                              <fo:footnote>
                                    <fo:inline/>
                                    <fo:footnote-body>
                                          <fo:block>
                                                <fo:leader
xsl:use-attribute-sets="MediumLeader"/>
                                                <xsl:apply-templates select
="//FrontMatter/Disclaimer"/>
                                          </fo:block>
                                    </fo:footnote-body>
                              </fo:footnote>
                        </fo:flow>
                  </fo:page-sequence>
                  <fo:page-sequence master-reference="
Chapter-SequenceOddEven" initial-page-number="1" format="i"
force-page-count="end-on-even">
                        <fo:static-content flow-name="HeaderEven">
                              <fo:block xsl:use-attribute-sets="
PageNumberLeft">
                                    <fo:page-number/>
                              </fo:block>
                              <fo:block>
                                    <fo:retrieve-marker retrieve-class-name
="HeaderText" retrieve-boundary="page-sequence"/>
                              </fo:block>
                        </fo:static-content>
                        <fo:static-content flow-name="HeaderOdd">
                              <fo:block xsl:use-attribute-sets="
PageNumberRight">
                                    <fo:page-number/>
                              </fo:block>
                              <fo:block xsl:use-attribute-sets="TextRight">
                                    <fo:retrieve-marker retrieve-class-name
="HeaderText" retrieve-boundary="page-sequence"/>
                              </fo:block>
                        </fo:static-content>
                        <fo:static-content flow-name="Footer">
                              <fo:block>
                                    <fo:leader xsl:use-attribute-sets="
MediumLeader"/>
                              </fo:block>
                              <fo:block>
                                    <xsl:for-each select="
//FrontMatter/TitlePage/Footer/FooterImageContentPages">
                                          <xsl:apply-templates/>
                                    </xsl:for-each>
                              </fo:block>
                              <fo:block xsl:use-attribute-sets="SMIdFooter
">
                                    <xsl:value-of select="
//FrontMatter/TitlePage/Footer/SMId"/>
                              </fo:block>
                        </fo:static-content>
                        <fo:flow flow-name="Body">
                              <fo:marker marker-class-name="HeaderText">
                                    <fo:inline xsl:use-attribute-sets="
TextItalic">
                                          <xsl:text>Contents</xsl:text>
                                    </fo:inline>
                              </fo:marker>
                              <fo:block xsl:use-attribute-sets="
ChapterTitle">
                                    <xsl:text>Contents</xsl:text>
                              </fo:block>
                              <!--Start TOC Section-->
                              <xsl:apply-templates select="
//CourseIntroduction | //CourseOverview | //CourseGoals |
//CourseInformation | //Audience | //Prerequisites | //Required |
//Recommended | //Materials | //GeneralInfo/CuInline |
//GeneralInfo/CuInline/ContentUnit/CuContent/Concept/ConceptBody/subcontent/subheading
 | //Agenda | //CourseLength | //Day1 | //Day2 | //Day3 | //Day4 | //Day5 |
//CompanyInformation/CuInline |
//CompanyInformation/CuInline/ContentUnit/CuContent/Concept/ConceptBody/subcontent/subheading
 | //Lesson
" mode="toc"/>
                              <!--End Toc Section-->
                        </fo:flow>
                  </fo:page-sequence>
                  <!--End TOC-->
                  <fo:page-sequence master-reference="
Chapter-SequenceOddEven" initial-page-number="1">
                        <fo:static-content flow-name="HeaderEven">
                              <fo:block xsl:use-attribute-sets="
PageNumberLeft">
                                    <fo:page-number/>
                              </fo:block>
                              <fo:block>
                                    <fo:retrieve-marker retrieve-class-name
="HeaderText" retrieve-boundary="page-sequence"/>
                              </fo:block>
                        </fo:static-content>
                        <fo:static-content flow-name="HeaderOdd">
                              <fo:block xsl:use-attribute-sets="
PageNumberRight">
                                    <fo:page-number/>
                              </fo:block>
                              <fo:block xsl:use-attribute-sets="TextRight">
                                    <fo:retrieve-marker retrieve-class-name
="HeaderText" retrieve-boundary="page-sequence"/>
                              </fo:block>
                        </fo:static-content>
                        <fo:static-content flow-name="Footer">
                              <fo:block>
                                    <fo:leader xsl:use-attribute-sets="
MediumLeader"/>
                              </fo:block>
                              <fo:block xsl:use-attribute-sets="TextCenter
">
                                    <xsl:for-each select="
//FrontMatter/TitlePage/Footer/FooterImageContentPages">
                                          <xsl:apply-templates/>
                                    </xsl:for-each>
                              </fo:block>
                              <fo:block xsl:use-attribute-sets="SMIdFooter
">
                                    <xsl:value-of select="
//FrontMatter/TitlePage/Footer/SMId"/>
                              </fo:block>
                        </fo:static-content>
                        <fo:flow flow-name="Body">
                              <fo:marker marker-class-name="HeaderText">
                                    <fo:inline xsl:use-attribute-sets="
TextItalic">
                                          <xsl:text>Introduction</xsl:text>
                                    </fo:inline>
                              </fo:marker>
                              <fo:block xsl:use-attribute-sets="
ChapterTitle">
                                    <xsl:text>Introduction</xsl:text>
                              </fo:block>
                              <fo:block xsl:use-attribute-sets="BodyText">
                                    <xsl:for-each select="
//FrontMatter/CourseIntroduction">
                                          <xsl:apply-templates/>
                                    </xsl:for-each>
                              </fo:block>
                        </fo:flow>
                  </fo:page-sequence>
                  <!--End FrontMatter Section-->
                  <!--Start Lesson Section-->
                  <fo:page-sequence master-reference="
Chapter-SequenceOddEven">
                        <fo:static-content flow-name="HeaderEven">
                              <fo:block xsl:use-attribute-sets="
PageNumberLeft">
                                    <fo:page-number/>
                              </fo:block>
                              <fo:block>
                                    <fo:retrieve-marker retrieve-class-name
="HeaderText" retrieve-boundary="page-sequence"/>
                              </fo:block>
                        </fo:static-content>
                        <fo:static-content flow-name="HeaderOdd">
                              <fo:block xsl:use-attribute-sets="
PageNumberRight">
                                    <fo:page-number/>
                              </fo:block>
                              <fo:block xsl:use-attribute-sets="TextRight">
                                    <fo:retrieve-marker retrieve-class-name
="HeaderText" retrieve-boundary="page-sequence"/>
                              </fo:block>
                        </fo:static-content>
                        <fo:static-content flow-name="Footer">
                              <fo:block>
                                    <fo:leader xsl:use-attribute-sets="
MediumLeader"/>
                              </fo:block>
                              <fo:block xsl:use-attribute-sets="TextCenter
">
                                    <xsl:for-each select="
//FrontMatter/TitlePage/Footer/FooterImageContentPages">
                                          <xsl:apply-templates/>
                                    </xsl:for-each>
                              </fo:block>
                              <fo:block xsl:use-attribute-sets="SMIdFooter
">
                                    <xsl:value-of select="
//FrontMatter/TitlePage/Footer/SMId"/>
                              </fo:block>
                        </fo:static-content>
                        <fo:flow flow-name="Body">
                              <fo:block xsl:use-attribute-sets="BodyText">
                                    <xsl:apply-templates select="//Lesson"
mode="Activity"/>
                              </fo:block>
                        </fo:flow>
                  </fo:page-sequence>
                  <!--End Lesson Section-->
                  <!--Start Evaluation Section-->
                  <fo:page-sequence master-reference="RestOfChapter"
initial-page-number="1" format="1">
                        <fo:static-content flow-name="Header">
                              <fo:block xsl:use-attribute-sets="
PageNumberRight">
                                    <xsl:text>Page&#160;</xsl:text>
                                    <fo:page-number/>
                                    <xsl:text>&#160;of&#160;</xsl:text>
                                    <fo:page-number-citation ref-id="
EndOfEvaluation"/>
                              </fo:block>
                        </fo:static-content>
                        <fo:static-content flow-name="Footer">
                              <fo:block>
                                    <fo:leader xsl:use-attribute-sets="
MediumLeader"/>
                              </fo:block>
                              <fo:block xsl:use-attribute-sets="TextCenter
">
                                    <xsl:for-each select="
//FrontMatter/TitlePage/Footer/FooterImageContentPages">
                                          <xsl:apply-templates/>
                                    </xsl:for-each>
                              </fo:block>
                              <fo:block xsl:use-attribute-sets="SMIdFooter
">
                                    <xsl:value-of select="
//FrontMatter/TitlePage/Footer/SMId"/>
                              </fo:block>
                        </fo:static-content>
                        <fo:flow flow-name="Body">
                              <fo:block xsl:use-attribute-sets="
EvaluationText">
                                    <xsl:apply-templates select="
//Evaluation"/>
                              </fo:block>
                              <fo:block id="EndOfEvaluation"/>
                              <fo:footnote>
                                    <fo:inline/>
                                    <fo:footnote-body>
                                          <fo:block xsl:use-attribute-sets
="EvaluationFootnote">
                                                <xsl:text>Thank you for
completing the Student Course Evaluation.</xsl:text>
                                          </fo:block>
                                          <fo:block xsl:use-attribute-sets
="EvaluationFootnote2">
                                                <xsl:text>Your feedback
will help us ensure the quality of the course.</xsl:text>
                                          </fo:block>
                                    </fo:footnote-body>
                              </fo:footnote>
                        </fo:flow>
                  </fo:page-sequence>
            </fo:root>
      </xsl:template>
      <!--End Evalution Section-->

Please accept my apologies if I am not describing my issue very well.
Thanks for your help!
Sharon


                                                                           
             "G. Ken Holman"                                               
             <gkholman@CraneSo                                             
             ftwrights.com>                                             To 
                                       xsl-list@xxxxxxxxxxxxxxxxxxxxxx     
             09/19/2007 05:36                                           cc 
             PM                                                            
                                                                   Subject 
                                       Re: [xsl] Using for-each w/         
             Please respond to         page-sequence results in "NC105 ID  
             xsl-list@xxxxxxxx         already exists in this document"    
              lberrytech.com           error                               
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




At 2007-09-19 16:53 -0400, Sharon_Harris@xxxxxxxxxxxxxxxxxxxx wrote:
>I am unable to generate a PDF file using a for-each loop before a page
>sequence if I am using IDs.I am using XSLT 1.0 and Apache FOP.

There is no relationship between XSLT's for-each and XSL-FO's
page-sequence.

To diagnose your situation, use XSLT to create an instance of XSL-FO
and then inspect XSL-FO to determine what the problem is.  That will
then tell you where you went wrong in your XSLT.

>I have a couple of page sequences defined. In 1 page sequence, I have a
TOC
>with IDs that point to elements that are outputted in a 2nd page sequence.

Those should be ref-id= attributes and not id= attributes.  Check
your XSL-FO instance to make sure <page-number-citation> is using ref-id=.

>The 2nd page sequence is for Lessons and starts with a for-each loop
>calling a Lesson element that will output all the lesson content within
the
>body of the Lesson page sequence. However, I encounter the following
error:
>"NC105 ID already exists in this document".

This tells me that when you open up the generated XSL-FO file you
will find id= being used more than once.

>I have unique ID prefixes specified in all Lesson children elements that
>are to be listed in the TOC so I am unsure why the IDs are repeated for
>each instance of the Lesson element.
>
>I have tried creating the Lesson page sequence without using a for-each
>loop and merely using <apply-templates select="//Lesson" mode="activity">

Note that the use of "//" is the most common way of making a very
inefficient stylesheet.  If you think you need "//", think again
because you may not need to incur the overhead.

>and this outputs fine except that the page sequence instructions do not
>repeat for every instance of the Lesson element. For example, I specify
>that the 1st page of each lesson should not have a header but only the 1st
>instance of the Lesson element has no header displaying but all other
>Lesson element instances have a header on the 1st page. But I do not run
>into the issue that the IDs are not unique for each instance of a Lesson
>element.

By not including a code fragment from your stylesheet, it is not
possible to comment on where you might be wrong.

>Am I correct in thinking that in order to get the page sequence to start
>over for each instance of the Lesson element, that I need to have a
>for-each statement before the page sequence?

No, that is not correct.  Any XSLT instruction at all can be used to
create any XSL-FO instruction at all.  In fact, you don't need XSLT
(I have a Python program on my web site that uses XSL-FO as a page
layout language, with no XSLT involved whatsoever).

In fact, a "push-oriented" stylesheet using <xsl:apply-templates/>
can in many ways be more flexible and maintainable than a
"pull-oriented" stylesheet using <xsl:for-each>.

>If so, how do I ensure the IDs are unique for every instance of the
>Lesson element?

By inspecting the XSL-FO instance to determine where your duplicate
identifiers are being specified using id=, and then finding where in
your XSLT the result tree with those extraneous identifiers are being
generated, then changing the XSLT accordingly.

I hope this helps.

. . . . . . . . . . . Ken

--
Upcoming public training: UBL and code lists Oct 1/5; Madrid Spain
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Jul'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread