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.

HomeHomeScryberScryberDevelopment Que...Development Que...Nested ForeachNested Foreach
Previous
 
Next
New Post
5/4/2016 2:10 PM
 

I'm trying to produce a PDF with some nested foreach statements, and I'm really struggling to get it to work properly. 

Here's some simplified (siblings removed for brevity) XML:

<?xml version="1.0" encoding="utf-8"?>

<AflAssessment >

  <Class ClassID="0" ClassName="" ClassColor="">

    <Students>

      <AflStudent StudentId="92">

        <Summaries>

          <AflSummary>

            <Questions>

              <AflQuestion QuestionId="61" QuestionNumber="1 Personal Engagement" QuestionName="1 Personal Engagement" QuestionMaxMarks="2" QuestionScore="2">

              </AflQuestion>

<AflQuestion QuestionId="61" QuestionNumber="1 Personal Engagement" QuestionName="1 Personal Engagement" QuestionMaxMarks="2" QuestionScore="2">

              </AflQuestion>

              </Questions>

          </AflSummary>

        </Summaries>

      </AflStudent>

    </Students>

  </Class>

</AflAssessment>

 

What I would like to do is have a section for each Student, and then inside that section, I would like to loop through the aflQuestions & display some child data. Here's what I have so far (all nested directly inside <pages> element: 

 <data:ForEach select="AflAssessment/Class/Students/AflStudent" datasource-id="Assessment">

        <Template>

          <pdf:Section>

            <Content>

              Student info here - This works perfectly

            <data:ForEach select="Summaries/AflSummary/Questions/AflQuestion" datasource-id="Assessment" >

            <Template>

              Question stuff here - this does not

            </Template>

          </data:ForEach>

          </Content>

          </pdf:Section>

        </Template>

      </data:ForEach>

The outer loop works fine, but I've tried just about every xpath permutation for the inner loop with no success; I think I'm probably missing something obvious and I'd be grateful if anyone has any thoughts. Once I get this figured out I'll have to do the same again for some stuff inside AflQuestion,.

 
New Post
5/5/2016 6:18 PM
 

Hi

There is an implicit data context when looping over items and binding to values.
So inside a ForEach component you will always be referring to the current node, unless you explicitly declare a separate source.

By declaring your datasource-id on the inner ForEach, scryber is going back to the original data and starting again.

If you remove the datasource-id attribute from the inner ForEach it should bind perfectly to the current node from the outer ForEach.

<data:ForEach select="AflAssessment/Class/Students/AflStudent" datasource-id="Assessment">

        <Template>

          <pdf:Section>

            <Content>

              Student info here - This works perfectly

            <data:ForEach select="Summaries/AflSummary/Questions/AflQuestion" >

            <Template>

              Question stuff here - this does not

            </Template>

          </data:ForEach>

          </Content>

          </pdf:Section>

        </Template>

      </data:ForEach>


 
Previous
 
Next
HomeHomeScryberScryberDevelopment Que...Development Que...Nested ForeachNested Foreach