Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looping inside child nodes instead of xsl:for-each

Status
Not open for further replies.

munnanext

Programmer
Aug 20, 2004
49
US
Hi Everyone,

I am generating a pdf document from the xml. The xml is dynamically generated and i am using this xml tree to generate pdf documents using xslt and xpath.

Here is my xml document.
Code:
<Details>
    <Date>Today's Date</Date> 
    <YearlyAmount>
	<DATES>
  		<DATE ID="03-JUN"  TYPE="Credit card" /> 
  		<DATE ID="06-JUN"  TYPE="Cash" /> 
  	</DATES>
        <MonthlyExpenses id="0001" DESCRIPTION="January">

	   <Purchases id="01" DESCRIPTION="Gas">
  	   	<AMOUNT>0</AMOUNT> 
  		<AMOUNT>0</AMOUNT> 
  	   </Purchases>
  	  <Purchases id="02" DESCRIPTION="Food">
  		<AMOUNT>0</AMOUNT> 
  		<AMOUNT>0</AMOUNT> 
  	  </Purchases>
  	 <Purchases id="03" DESCRIPTION="Jewellery">
  		<AMOUNT>0</AMOUNT> 
  		<AMOUNT>0</AMOUNT> 
  	 </Purchases>
	 <Purchases id="04" DESCRIPTION="Shoes">
  		<AMOUNT>0</AMOUNT> 
  		<AMOUNT>0</AMOUNT> 
    	</Purchases>
	<Purchases id="05" DESCRIPTION="Watch">
  		<AMOUNT>0</AMOUNT> 
  		<AMOUNT>0</AMOUNT> 
  	</Purchases>
 	<TOTALS>
  		<AMOUNT>0.0</AMOUNT> 
  		<AMOUNT>0.0</AMOUNT> 
  	</TOTALS>
     </MonthlyExpenses>

     <MonthlyExpenses id="0002" DESCRIPTION="Feburary">

	<Purchases id="01" DESCRIPTION="Gas">
  		<AMOUNT>0</AMOUNT> 
  		<AMOUNT>0</AMOUNT> 
  	</Purchases>
 	<Purchases id="02" DESCRIPTION="Food">
 		 <AMOUNT>0</AMOUNT> 
  		<AMOUNT>0</AMOUNT> 
  	</Purchases>
	<Purchases id="03" DESCRIPTION="Jewellery">
  		<AMOUNT>0</AMOUNT> 
  		<AMOUNT>0</AMOUNT> 
  		</Purchases>
	<Purchases id="04" DESCRIPTION="Shoes">
  		<AMOUNT>0</AMOUNT> 
  		<AMOUNT>0</AMOUNT> 
  	</Purchases>
	<Purchases id="05" DESCRIPTION="Watch">
  		<AMOUNT>0</AMOUNT> 
  		<AMOUNT>0</AMOUNT> 
  	</Purchases>
 	<TOTALS>
  		<AMOUNT>0.0</AMOUNT> 
  		<AMOUNT>0.0</AMOUNT> 
  	</TOTALS>
     </MonthlyExpenses>
  </YearlyAmount>
</Details>

And here is my XSL file.

I am sending the code from the flow region..

Code:
<fo:flow flow-name="xsl-region-body">
	<fo:block>
		<xsl:for-each select="//YearlyAmount">
			<fo:table width="100%">
				<fo:table-column column-width="9cm" />
				<xsl:for-each select="DATES/DATE">
					<fo:table-column column-width="4cm" />
				</xsl:for-each>
				<fo:table-column column-width="7cm" />
				<fo:table-header>
					<fo:table-row font-size="16pt" padding-before="2pt" padding-after="2pt" >
						<fo:table-cell display-align="center">
							<fo:block text-align="center">Items Purchased</fo:block>
						</fo:table-cell>
						<xsl:for-each select="DATES/DATE">
							<fo:table-cell display-align="center">
								<fo:block text-align="center">
									<xsl:value-of select="@ID" />
								</fo:block>
							</fo:table-cell>
						</xsl:for-each>
						<fo:table-cell  display-align="center">
							<fo:block text-align="center" >Grand Total</fo:block>
						</fo:table-cell>
					</fo:table-row>
									
					<fo:table-row font-size="16pt" padding-before="2pt" padding-after="2pt">
						<fo:table-cell display-align="center" >
							<fo:block text-align="center">
								<fo:block></fo:block>
							</fo:block>
						</fo:table-cell>
						<xsl:for-each select="DATES/DATE">
							<fo:table-cell  display-align="center">
								<fo:block text-align="center">
									<xsl:value-of select="@TYPE" />
								</fo:block>
							</fo:table-cell>
						</xsl:for-each>
					</fo:table-row>
				</fo:table-header>
				<fo:block padding-before="2pt" padding-after="2pt" />
				<fo:table-body>
					<xsl:for-each select="MonthlyExpenses">
						<xsl:for-each select="Purchases">
							<fo:table-row font-size="16pt" space-before="3pt" space-after="3pt">
								<fo:table-cell display-align="center">
									<fo:block text-align="left">
										<fo:inline font-weight="bold">
											<xsl:value-of select="@DESCRIPTION"/>
										</fo:inline>
									</fo:block>
								</fo:table-cell>
								<xsl:for-each select="AMOUNT">
									<fo:table-cell padding-start="3pt" padding-end="3pt" padding-before="3pt" padding-after="3pt" display-align="center">
										<fo:block space-before="3pt" space-after="3pt" text-align="center">
											<fo:inline font-weight="bold">
												<xsl:value-of select="."/>
											</fo:inline>
										</fo:block>
									</fo:table-cell>
								</xsl:for-each>
								<fo:table-cell display-align="center">
									<fo:block text-align="center">
										<xsl:value-of select="sum(AMOUNT)"/>
									</fo:block>
								</fo:table-cell>
								</fo:table-row>
								</xsl:for-each>
								<fo:table-row font-size="16pt" keep-with-previous="always">
									<fo:table-cell display-align="center">
										<fo:block text-allign="left">
											<xsl:value-of select="@DESCRIPTION"/>
										</fo:block>
									</fo:table-cell>
										<xsl:for-each select="TOTALS">
											<fo:table-cell padding-start="3pt" padding-end="3pt" padding-before="3pt" padding-after="3pt" display-align="right" >
												<fo:block space-before="3pt" space-after="3pt" text-align="center">
													<fo:inline font-weight="bold">
														<xsl:apply-templates select ="AMOUNT"/>
													</fo:inline>
												</fo:block>
											</fo:table-cell>
											<fo:table-cell padding-start="3pt" padding-end="3pt" padding-before="3pt" padding-after="3pt" display-align="center">
												<fo:block space-before="3pt" space-after="3pt" text-align="center">
													<xsl:value-of select="sum(child::AMOUNT)"/>
												</fo:block>
											</fo:table-cell>
										</xsl:for-each>
									</fo:table-row>
								</xsl:for-each>
							</fo:table-body>
						</fo:table>
					</xsl:for-each>
				</fo:block>
			<fo:block id="end"/>
		</fo:flow>


I am able to generate the pdf document, but if i am not using <xsl:for-each tag and using the xpath expressions to get the values of children from the TOTALS element, the out put is coming in the same line ie, instead of appearing in the different columns, the values are coming in the same column.
here is my code where i am using xpath expressions instead of xsl:for-each
Code:
<fo:table-cell padding-start="3pt" padding-end="3pt" padding-before="3pt" padding-after="3pt" display-align="center">
												<fo:block space-before="3pt" space-after="3pt" text-align="center">
													<xsl:value-of select="sum(child::AMOUNT)"/>
												</fo:block>
											</fo:table-cell>
Can any one please explain me how to get the output in different columns instead of all the output printing in the same column, without using <xsl:for-each>

Sorry for the long post.
Thanks in Advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top