Background Color:
 
Background Pattern:
Reset
Search

Forum

Please Log In

We want you to contribute! 

This forum is a moderated environment. 
We try to keep it neat and tidy. In order to access the forum content we would like you to either or register.

HomeHomeScryberScryberIssues and Defe...Issues and Defe...data:ForEach table issuedata:ForEach table issue
Previous
 
Next
New Post
11/17/2015 3:32 AM
 

Hello, folks.

 I've been working with Scryber for about a week now, and it looks like it's EXACTLY what my project needs. I've conferred with the rest of the project team about purchasing a domain license or two, but before I went ahead and moved forward on that, I had an issue I was hoping to get some insight into (though it's probably something stupidly simple!)

I'm working in an ASP.NET/C# environment, and my data is being pulled from a MS-SQL database. I currently have my SQL query loading the results into a DataSet. However, I have a problem. When using data:ForEach to fill a table in the PDF with about 4-6 rows of data, it REPEATS the first row. This may be a problem with my XML as well, but if so, I was hoping someone might point me in the right direction as well.

I'm trying to user Scryber to generate a contract for our faculty and staff members. I have a dataset with their information, and using pdf:label, I have their information coming into the PDF fine. However, I have a table I want to insert, that could be anywhere between 1-6 (usually) rows of the COURSES this contract is for. My query pulls the Course ID (CRN, which is the PRIMARY KEY, but will not appear in the actual contract,) course title, credit hours, compensation, time, etc.  for every course in our database where our Employee's ID# is listed as the Instructor.  But when I use a data:foreach in the table, like the demo on the Scryber wiki and the one codeplex sample I found, the table just repeats the FIRST course, not any of the others, though sometimes, it will repeat that data NUMEROUS times. Like, in one case, I have an XML document with four courses, and the table will be filled with four rows, but every row is just a copy of the first row. I REALLY want to figure this out, but after a couple of days of searching and trying, I haven't been able to either solve this myself, or find anywhere else online that may have a solution. You can find samples of the XML document and my code-behind below. Any insight would be appreciated. It's probably simple--this is my first time utilizing XML in anything but  the most basic manner.

 <?xml version="1.0" standalone="yes"?>
<DocumentElement>
  <myTable>
    <CRN>13119</CRN>
    <CourseCode>HIST</CourseCode>
    <CourseSection>HIST105-1</CourseSection>
    <CourseTitle>SURVEY OF AFRICAN HISTORY</CourseTitle>
    <Credits>3.00</Credits>
    <Compensation>2550.00</Compensation>
    <DaysofCourse>TR</DaysofCourse>
    <Time>1100 - 1215</Time>
  </myTable>
  <myTable>
    <CRN>20570</CRN>
    <CourseCode>HIST</CourseCode>
    <CourseSection>HIST105-2</CourseSection>
    <CourseTitle>SURVEY OF AFRICAN HISTORY</CourseTitle>
    <Credits>3.00</Credits>
    <Compensation>2550.00</Compensation>
    <DaysofCourse>TR</DaysofCourse>
    <Time>1230 - 1345</Time>
  </myTable>

<myTable>//Repeat for "X" number of records" </myTable>
</DocumentElement>

 

And in my .pdfx file for generating the table: (I have two XML sources listed in the document elsewhere)

<pdf:Div style:class="course-information" style:font-bold="true" style:margins="20pt">
          Course Information
          <data:ForEach select="DocumentElement" datasource-id="CourseXmlSource">
            <Template>
              <pdf:Table id="coursegrid" style:full-width="true" style:font-size="8pt">
                <pdf:Header-Row>
                  <pdf:Header-Cell>Course Code</pdf:Header-Cell>
                  <pdf:Header-Cell>Course and Section</pdf:Header-Cell>
                  <pdf:Header-Cell>Course</pdf:Header-Cell>
                  <pdf:Header-Cell>Credits</pdf:Header-Cell>
                  <pdf:Header-Cell>Compensation</pdf:Header-Cell>
                  <pdf:Header-Cell>Days of Week</pdf:Header-Cell>
                  <pdf:Header-Cell>Time</pdf:Header-Cell>
                </pdf:Header-Row>
                <data:ForEach select="//myTable//CRN">
                  <Template>
                    <pdf:Row>
                      <pdf:Cell>
                        <pdf:Label text="{xpath:/DocumentElement/myTable/CourseCode}" />
                      </pdf:Cell>
                      <pdf:Cell>
                        <pdf:Label text="{xpath:/DocumentElement/myTable/CourseSection}" />
                      </pdf:Cell>
                      <pdf:Cell>
                        <pdf:Label text="{xpath:/DocumentElement/myTable/CourseTitle}" />
                      </pdf:Cell>
                      <pdf:Cell>
                        <pdf:Label text="{xpath:/DocumentElement/myTable/Credits}" />
                      </pdf:Cell>
                      <pdf:Cell>
                        <pdf:Label text="{xpath:/DocumentElement/myTable/Compensation}" />
                      </pdf:Cell>
                      <pdf:Cell>
                        <pdf:Label text="{xpath:/DocumentElement/myTable/DaysofCourse}" />
                      </pdf:Cell>
                      <pdf:Cell>
                        <pdf:Label text="{xpath:/DocumentElement/myTable/Time}" />
                      </pdf:Cell>
                    </pdf:Row>
                  </Template>
                </data:ForEach>
              </pdf:Table>
            </Template>
          </data:ForEach>
        </pdf:Div>






 
New Post
11/18/2015 6:37 AM
 

Hi

It is very close to working, but your x-path statements are a bit skewed. The inner ForEach will be looping over the Table/CRN elements, but the label bindings are then going back up to the top of the document and getting the first matching item in DocumentElement/myTable/CourseCode etc.

Here's a sample that worked for me where the inner ForEach is looping over the myTable elements and the labels in the cells are selecting inner elements of that myTable...

    <pdf:Div style:class="course-information" style:font-bold="true" style:margins="20pt">

          Course Information

          <data:ForEach select="/DocumentElement" datasource-id="CourseXmlSource">

            <Template>

              <pdf:Table id="coursegrid" style:full-width="true" style:font-size="8pt">

                <pdf:Header-Row>

                  <pdf:Header-Cell>Course Code</pdf:Header-Cell>

                  <pdf:Header-Cell>Course and Section</pdf:Header-Cell>

                  <pdf:Header-Cell>Course</pdf:Header-Cell>

                  <pdf:Header-Cell>Credits</pdf:Header-Cell>

                  <pdf:Header-Cell>Compensation</pdf:Header-Cell>

                  <pdf:Header-Cell>Days of Week</pdf:Header-Cell>

                  <pdf:Header-Cell>Time</pdf:Header-Cell>

                </pdf:Header-Row>

                <data:ForEach select="myTable">

                  <Template>

                    <pdf:Row>

                      <pdf:Cell>

                        <pdf:Label text="{xpath:CourseCode}" />

                      </pdf:Cell>

                      <pdf:Cell>

                        <pdf:Label text="{xpath:CourseSection}" />

                      </pdf:Cell>

                      <pdf:Cell>

                        <pdf:Label text="{xpath:CourseTitle}" />

                      </pdf:Cell>

                      <pdf:Cell>

                        <pdf:Label text="{xpath:Credits}" />

                      </pdf:Cell>

                      <pdf:Cell>

                        <pdf:Label text="{xpath:Compensation}" />

                      </pdf:Cell>

                      <pdf:Cell>

                        <pdf:Label text="{xpath:DaysofCourse}" />

                      </pdf:Cell>

                      <pdf:Cell>

                        <pdf:Label text="{xpath:Time}" />

                      </pdf:Cell>

                    </pdf:Row>

                  </Template>

                </data:ForEach>

              </pdf:Table>

            </Template>

          </data:ForEach>

        </pdf:Div>


 
New Post
11/18/2015 2:05 PM
 

Ah, thank you so much! I knew it had to be something simple. I've spent the last couple of days diving through Xpath documentation, too. 

Now I've just gotta format the cells so that the values are centered vertically in each cell--and we can generate a few samples. If all goes well, it looks like Scryber will be our choice for production. Again, thanks so much!

 
Previous
 
Next
HomeHomeScryberScryberIssues and Defe...Issues and Defe...data:ForEach table issuedata:ForEach table issue