[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

XSL : want to control the table row display

Posted on 2004-11-10
9
Medium Priority
?
272 Views
Last Modified: 2010-05-18
Following is my xml structure:

<Questions>
       <Question no="1" verbiage="Enter your Name">
           <Answers>
           <Answer> "x"</Answer>
           <Answer> "y"</Answer>
           </Answers>
       </Question>
       <Question no="2" verbiage="Enter your City">
           <Answers>
           <Answer> "cccc"</Answer>
           </Answers>
       </Question>
       <Question no="3" verbiage="Enter your State">
           <Answers>
           <Answer> "NJ"</Answer>
           </Answers>
       </Question>
       <Question no="4" verbiage="Enter your Country">
           <Answers>
           <Answer> "USA"</Answer>
           </Answers>
       </Question>
</Questions>

I am having 500 questions in my xml file.When a question is a 4 line text, part of the question is rendered in first page and another part in second page.I just want to display that particular row in either 1st page or 2nd page. I am using  <fo:table>
not html <TABLE>.

0
Comment
Question by:jaffersathick
  • 7
  • 2
9 Comments
 
LVL 2

Expert Comment

by:htang_us
ID: 12555776
Don't quite understand your question.

What's your expected output? a question.fo file? You want to generate PDF file?

Which part do you want to put in first page and which in second page?
0
 
LVL 2

Expert Comment

by:htang_us
ID: 12555870
Is this your school homework?
0
 
LVL 2

Expert Comment

by:htang_us
ID: 12555958
which is your "paticular row"? how do you decide it?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:jaffersathick
ID: 12556764
I am generating a pdf thru Apache FOP.My flow of execution is  XML and XSLT are the inputs for XSLT engine and it generates a XSLFO document which is fed to FOP that in turn generates PDF.So basically i have to create the xslt file for this process.

WHICH ROW?
My wish is no single row should partially appear in two pages.It should be a complete row either in page'X' or page'Y'.

example
<Questions>
       <Question no="1" verbiage=""If person1 does not administer the mental/nervous benefit, has the customer
                                                   agrees to provide eligibility to the non-person mental health benefit administrator.">
           <Answers>
           <Answer> "x"</Answer>
           <Answer> "y"</Answer>
           </Answers>
       </Question>
</Question>.

In my pdf the above Question Verbiage appears as

page X:
1            If person1 does not administer                 x,y
              the mental/nervous              

page Y:(Remaining part)
             benefit, has the customer agrees
             to provide eligibility to the non-person
             mental health benefit administrator.">
 
I just want the above not to split up in two pages.
Hope you understand this time.
0
 
LVL 2

Expert Comment

by:htang_us
ID: 12557485
Here you go

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
      
      <xsl:template match="/input">
            <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
                  <fo:layout-master-set>
                        <fo:simple-page-master master-name="first" page-height="11in" page-width="8.5in" margin-top="1in" margin-bottom="1in" margin-left="1in" margin-right="1in">
                              <fo:region-body margin-top="0.5in"></fo:region-body>
                              <fo:region-before extent="0.5in"/>
                        </fo:simple-page-master>
                  </fo:layout-master-set>
      
                  <fo:page-sequence master-reference="first">
                        <fo:static-content flow-name="xsl-region-before">
                              <fo:block font-size="15pt" font-weight="bold" text-align="center">Questions</fo:block>
                        </fo:static-content>
                              
                        <fo:flow flow-name="xsl-region-body">
                              <fo:block font-size="10pt" line-height="12pt" id="define-toc">
                                    <fo:table table-layout="fixed">
                                          <fo:table-column column-width="3in"/><!-- Question -->
                                          <fo:table-column column-width="3in"/><!-- Answer -->
                                          
                                          <fo:table-header>
                                                <fo:table-row font-size="12pt" font-weight="bold"  line-height="15pt">
                                                      <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid" background-color="#dddddd">
                                                            <fo:block>Question</fo:block>
                                                      </fo:table-cell>
                                                      <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid" background-color="#dddddd">
                                                            <fo:block>Answer</fo:block>
                                                      </fo:table-cell>
                                                </fo:table-row>
                                          </fo:table-header>
                                          
                                          <fo:table-body font-size="10pt" line-height="12pt">
                                                <xsl:for-each select="Questions">
                                                      <fo:table-row keep-with-next="always">
                                                            <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                  <fo:block><xsl:value-of select="Question[@no=1]/@verbiage"/></fo:block>
                                                            </fo:table-cell>
                                                            <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                  <fo:block><xsl:value-of select="Question[@no=1]/Answers/Answer[1]"/></fo:block>
                                                            </fo:table-cell>
                                                      </fo:table-row>
                                                      <fo:table-row keep-with-next="always">
                                                            <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                  <fo:block><xsl:value-of select="Question[@no=2]/@verbiage"/></fo:block>
                                                            </fo:table-cell>
                                                            <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                  <fo:block><xsl:value-of select="Question[@no=2]/Answers/Answer[1]"/></fo:block>
                                                            </fo:table-cell>
                                                      </fo:table-row>
                                                      <fo:table-row keep-with-next="always">
                                                            <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                  <fo:block><xsl:value-of select="Question[@no=3]/@verbiage"/></fo:block>
                                                            </fo:table-cell>
                                                            <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                  <fo:block><xsl:value-of select="Question[@no=3]/Answers/Answer[1]"/></fo:block>
                                                            </fo:table-cell>
                                                      </fo:table-row>
                                                      <fo:table-row>
                                                            <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                  <fo:block><xsl:value-of select="Question[@no=4]/@verbiage"/></fo:block>
                                                            </fo:table-cell>
                                                            <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                  <fo:block><xsl:value-of select="Question[@no=4]/Answers/Answer[1]"/></fo:block>
                                                            </fo:table-cell>
                                                      </fo:table-row>
                                                      <fo:table-row keep-with-previous="always">
                                                            <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid" background-color="#d0d0d0">
                                                                  <fo:block>----</fo:block>
                                                            </fo:table-cell>
                                                            <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid"  background-color="#d0d0d0">
                                                                  <fo:block>----</fo:block>
                                                            </fo:table-cell>
                                                      </fo:table-row>
                                                </xsl:for-each>
                                          </fo:table-body>
                                    </fo:table>
                              </fo:block>
                        </fo:flow>
                  </fo:page-sequence>
            </fo:root>
      </xsl:template>
</xsl:stylesheet>
0
 
LVL 2

Expert Comment

by:htang_us
ID: 12557507
Forget to put your source files, I make a little change

<input>
      <Questions>
            <Question no="1" verbiage="Enter your Name">
                  <Answers>
                        <Answer> "x"</Answer>
                        <Answer> "y"</Answer>
                  </Answers>
            </Question>
            <Question no="2" verbiage="Enter your City">
                  <Answers>
                        <Answer> "cccc"</Answer>
                  </Answers>
            </Question>
            <Question no="3" verbiage="Enter your State">
                  <Answers>
                        <Answer> "NJ"</Answer>
                  </Answers>
            </Question>
            <Question no="4" verbiage="Enter your Country">
                  <Answers>
                        <Answer> "USA"</Answer>
                  </Answers>
            </Question>
      </Questions>

... here repeat questions element multiple times, so we can get multiple page output ...
</input>
0
 
LVL 2

Expert Comment

by:htang_us
ID: 12557583
If your input contains <Questions> as root element and all <Question> elements with "no" attribute running from 1 to 500. You just need to modify the original stylesheet for fo:table-body. It will somehow like this

<xsl:for-each select="Question">
  <xsl:if test="@no % 4 = 1">
                                                      <fo:table-row keep-with-next="always">
                                                            <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                  <fo:block><xsl:value-of select="@verbiage"/></fo:block>
                                                            </fo:table-cell>
                                                            <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                  <fo:block><xsl:value-of select="Answers/Answer[1]"/></fo:block>
                                                            </fo:table-cell>
                                                      </fo:table-row>

  </xsl:if>

... then repeat this for 2, 3, and 4's situations ...

</xsl:for-each>
0
 
LVL 2

Accepted Solution

by:
htang_us earned 2000 total points
ID: 12557743
Here is the solution for your original source file

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
      
      <xsl:template match="/Questions">
            <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
                  <fo:layout-master-set>
                        <fo:simple-page-master master-name="first" page-height="11in" page-width="8.5in" margin-top="1in" margin-bottom="1in" margin-left="1in" margin-right="1in">
                              <fo:region-body margin-top="0.5in"></fo:region-body>
                              <fo:region-before extent="0.5in"/>
                        </fo:simple-page-master>
                  </fo:layout-master-set>
      
                  <fo:page-sequence master-reference="first">
                        <fo:static-content flow-name="xsl-region-before">
                              <fo:block font-size="15pt" font-weight="bold" text-align="center">Questions</fo:block>
                        </fo:static-content>
                              
                        <fo:flow flow-name="xsl-region-body">
                              <fo:block font-size="10pt" line-height="12pt" id="define-toc">
                                    <fo:table table-layout="fixed">
                                          <fo:table-column column-width="3in"/><!-- Question -->
                                          <fo:table-column column-width="3in"/><!-- Answer -->
                                          
                                          <fo:table-header>
                                                <fo:table-row font-size="12pt" font-weight="bold"  line-height="15pt">
                                                      <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid" background-color="#dddddd">
                                                            <fo:block>Question</fo:block>
                                                      </fo:table-cell>
                                                      <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid" background-color="#dddddd">
                                                            <fo:block>Answer</fo:block>
                                                      </fo:table-cell>
                                                </fo:table-row>
                                          </fo:table-header>
                                          
                                          <fo:table-body font-size="10pt" line-height="32pt">
                                                <xsl:for-each select="Question">
                                                      <xsl:choose>
                                                            <xsl:when test="number(@no) mod 4=0">
                                                                  <fo:table-row>
                                                                        <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                              <fo:block><xsl:value-of select="@verbiage"/></fo:block>
                                                                        </fo:table-cell>
                                                                        <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                              <fo:block><xsl:value-of select="Answers/Answer[1]"/></fo:block>
                                                                        </fo:table-cell>
                                                                  </fo:table-row>
                                                                  <fo:table-row keep-with-previous="always">
                                                                        <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid" background-color="#d0d0d0">
                                                                              <fo:block>----</fo:block>
                                                                        </fo:table-cell>
                                                                        <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid"  background-color="#d0d0d0">
                                                                              <fo:block>----</fo:block>
                                                                        </fo:table-cell>
                                                                  </fo:table-row>
                                                            </xsl:when>
                                                            <xsl:otherwise>
                                                                  <fo:table-row keep-with-next="always">
                                                                        <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                              <fo:block><xsl:value-of select="@verbiage"/></fo:block>
                                                                        </fo:table-cell>
                                                                        <fo:table-cell border-color="#cccccc" border-width="0.5pt" border-style="solid">
                                                                              <fo:block><xsl:value-of select="Answers/Answer[1]"/></fo:block>
                                                                        </fo:table-cell>
                                                                  </fo:table-row>
                                                            </xsl:otherwise>
                                                      </xsl:choose>
                                                </xsl:for-each>
                                          </fo:table-body>
                                    </fo:table>
                              </fo:block>
                        </fo:flow>
                  </fo:page-sequence>
            </fo:root>
      </xsl:template>
</xsl:stylesheet>
0
 

Author Comment

by:jaffersathick
ID: 12598978
Thanks a lot for your help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question