[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Node Order and Value determination


Subject: RE: [xsl] Node Order and Value determination
From: "Josh Canfield" <Josh.Canfield@xxxxxxxxxxxx>
Date: Wed, 4 Feb 2004 12:48:21 -0800

The included files are neither complete nor simplified. 

Here is an example of simplified XML input:

<TABLE>
	<DPROW>
		<OBJECT></OBJECT>
	</DPROW>
	<TABLE>
		<DPROW>
			<OBJECT></OBJECT>
			<OBJECT></OBJECT>
		</DPROW>
	</TABLE>
</TABLE>

Here is an example of simplified XSL

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="FO">
<xsl:template match="TABLE">
  <fo:table>
    <xsl:apply-templates/>
  </fo:table>
</xsl:template>

<xsl:template match="DPROW">
  <fo:table-row>
    <xsl:apply-templates/>
  </fo:table-row>
</xsl:template>

<xsl:template match="OBJECT">
  <fo:table-column>
    <xsl:apply-templates/>
  </fo:table-column>
</xsl:template>

</xsl:stylesheet>

Here is an example of the output I get:

<?xml version="1.0" encoding="utf-8"?>
<fo:table xmlns:fo="FO">
  <fo:table-row>
    <fo:table-column/>
  </fo:table-row>
  <fo:table>
    <fo:table-row>
      <fo:table-column/>
      <fo:table-column/>
    </fo:table-row>
  </fo:table>
</fo:table>

Using this example, what is the output that you want to get?

Josh

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of scott
gabelhart
Sent: Wednesday, February 04, 2004 11:11 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Node Order and Value determination


Jarno.Elovirta@xxxxxxxxx wrote:

>Hi,
>
>  
>
>>thanks for the timely reply. The problem is your suggestion doesn't 
>>solve my problem.
>>
>>I want my xml structure when being transformed to determine for each 
>><OBJECT> element the creation of a corresponding <fo:table-column>
>>
>>transform code snippet
>>
>><xsl:template match="TABLE">
>>        <fo:table table-layout="fixed" width="7.5in" 
>>space-before.optimum="5pt">
>>           
>>           
>>            <!--xsl:call-template name="for-loop"/-->
>>            <!--xsl:call-template name="build-columns"/-->
>>             <xsl:for-each select="TABLE/DPROW/OBJECT">
>>    
>>
>
>This should be
>
>  <xsl:for-each select="DPROW/OBJECT">
>
>  
>
>>                        <fo:table-column column-width="{6.26 div 
>>last()}in"/>
>>             </xsl:for-each>
>>
>>           
>>            <fo:table-body>
>>                <xsl:apply-templates select="*"/>
>>            </fo:table-body>
>>        </fo:table>
>>    </xsl:template>
>>creates in my output hundreds of fo:table-column tags.
>>
>>xml input file snippet
>>
>><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="842" 
>>OCCURENCE="2">
>>                    <DPROW>
>>                        <OBJECT ALIGN="left" WIDTH="3"/>
>>                        <OBJECT>
>>                            <TABLE WIDTH="100%" BORDER="0" 
>>CELLSPACING="0" CELLPADDING="0" OCCURENCE="2">
>>                                <DPROW>
>>                                    <OBJECT WIDTH="4" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="22" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="67" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="2" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="211" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="2" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="273" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="48" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="92" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="2" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="2" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="82" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="6" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="22" HEIGHT="6"/>
>>                                    <OBJECT WIDTH="5" HEIGHT="6"/>
>>                                </DPROW>
>>For the first TABLE/DPROW/OBJECT containing two object 
>>elements I would 
>>need to create two corresponding fo:table-column tags and for the 
>>second  TABLE/DPROW/OBJECT containing fifteen object elements I would 
>>need to create fifteen corresponding fo:table-column tags.
>>    
>>
>
>What does it create then if not that (after the fix mentioned above)?
> 
>  
>
>>What am I doing wrong in the XPath declaration?
>>    
>>
>
>It's called "XPath expression". If your stylesheet still doesn't work, please send a complete, simplified example source document with the stylesheet you have so far, *and* example of the desired output.
>
>Cheers,
>
>Jarno - Melotron: Kein Problem (Problemzonen-Mix)
>
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>  
>
Jarno,

thanks for the response.  I tried your most current suggestion 
previously myself and I am still getting the wrong result.

My xml input file is modeled very closely against html a html <table> is 
a <TABLE>; a <tr> is a <DPROW>, and a <td> is a <OBJECT>.

My xml input file has nested html tables and that is where the problem 
is coming in when trying to transform this particular input file.

I have attached my xslt, along with partial xml input file and output. 
What I need to determine for my xsl:fo output is between the start of a 
<TABLE> element in my input file and either the start of a new <TABLE> 
or <DPROW> element how many <OBJECT> elements were contained. Example

<TABLE><DPROW><OBJECT></OBJECT></DPROW></TABLE> should yield one 
fo:table-column.
<TABLE><DPROW><OBJECT></OBJECT></DPROW><TABLE><DPROW><OBJECT></OBJECT><OBJECT></OBJECT></DPROW></TABLE>
should yield two fo:table-column for the inner table and a single 
fo:table-column for the outer table.

Essential in XPath how do I inspect from one <TABLE> element to either 
the ending </DPROW> of corresponding closing </TABLE> element the number 
of <OBJECT> elements.

xml input file:
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" OCCURENCE="1">
                    <DPROW>
                        <OBJECT ALIGN="left" 
STYLE="background-color:#FFFFFF;" HEIGHT="10"/>
                    </DPROW>
                </TABLE>
                <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" 
WIDTH="842" OCCURENCE="2">
                    <DPROW>
                        <OBJECT ALIGN="left" WIDTH="3"/>
                        <OBJECT>
                            <TABLE WIDTH="100%" BORDER="0" 
CELLSPACING="0" CELLPADDING="0" OCCURENCE="2">
                                <DPROW>
                                    <OBJECT WIDTH="4" HEIGHT="6"/>
                                    <OBJECT WIDTH="22" HEIGHT="6"/>
                                    <OBJECT WIDTH="67" HEIGHT="6"/>
                                    <OBJECT WIDTH="2" HEIGHT="6"/>
                                    <OBJECT WIDTH="211" HEIGHT="6"/>
                                    <OBJECT WIDTH="2" HEIGHT="6"/>
                                    <OBJECT WIDTH="273" HEIGHT="6"/>
                                    <OBJECT WIDTH="48" HEIGHT="6"/>
                                    <OBJECT WIDTH="92" HEIGHT="6"/>
                                    <OBJECT WIDTH="2" HEIGHT="6"/>
                                    <OBJECT WIDTH="2" HEIGHT="6"/>
                                    <OBJECT WIDTH="82" HEIGHT="6"/>
                                    <OBJECT WIDTH="6" HEIGHT="6"/>
                                    <OBJECT WIDTH="22" HEIGHT="6"/>
                                    <OBJECT WIDTH="5" HEIGHT="6"/>
                                </DPROW>
                                <DPROW>
                                    <OBJECT WIDTH="4"/>
                                    <OBJECT WIDTH="22"/>
                                    <OBJECT WIDTH="67" VALIGN="top">
                                        <TABLE BORDER="0" WIDTH="66" 
OCCURENCE="2">
                                            <DPROW>
                                                <OBJECT 
STYLE="color:#000000;font-family:Arial;font-size:10pt;background-color:#FFFFFF;height:20px;font-weight:bold;">Agent 
ID:</OBJECT>
                                            </DPROW>
                                        </TABLE>
                                    </OBJECT>
                                    <OBJECT WIDTH="2" COLSPAN="2" 
VALIGN="top">
                                        <TABLE BORDER="0" WIDTH="212" 
OCCURENCE="2">
                                            <DPROW>
                                                <OBJECT 
STYLE="color:#000000;font-family:Arial;font-size:12pt;background-color:#FFFFFF;height:20px;font-weight:bold;">100008</OBJECT>
                                            </DPROW>
                                        </TABLE>
                                    </OBJECT>
                                    <OBJECT WIDTH="2"/>
                                    <OBJECT WIDTH="273"/>
                                    <OBJECT WIDTH="48"/>
                                    <OBJECT WIDTH="92"/>
                                    <OBJECT WIDTH="2"/>
<..snip..>
xsl file

<?xml version="1.0"?>
<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" version="1.0" encoding="UTF-8" indent="yes"/>

    <!--sect 1-->
    <xsl:template match="/">
        <xsl:apply-templates select="WITAGLIB"/>
    </xsl:template>
    <xsl:template match="WITAGLIB">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
            <!--sect 2-->
            <fo:layout-master-set>
                <fo:simple-page-master master-name="all" 
page-height="11in" page-width="8.5in" margin-left=".25in" 
margin-right=".25in">
                    <fo:region-body region-name="all-body" 
margin-bottom=".55in" margin-top=".79in"/>
                    <fo:region-before region-name="all-before" 
extent="1in" display-align="after" padding="6pt 1in"/>
                    <fo:region-after region-name="all-after" 
extent="1in" display-align="before" padding="6pt 1in"/>
                </fo:simple-page-master>
                <!--sect 3-->
            </fo:layout-master-set>
            <fo:page-sequence master-reference="all">
                <xsl:apply-templates/>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
    <xsl:template match="FORMATTED">
<!-- ============================================
    Start generating the content for the main page
    area (xsl-region-body).
    =============================================== -->
        <fo:flow flow-name="all-body">
            <xsl:apply-templates/>
        </fo:flow>
    </xsl:template>
    <!--sect 4-->
    <xsl:template match="TABLE">
        <fo:table table-layout="fixed" width="7.5in" 
space-before.optimum="5pt">
           
           
         <xsl:for-each select="DPROW/OBJECT">
                <fo:table-column column-width="{6.26 div last()}in"/>
             </xsl:for-each>

           
            <fo:table-body>
               
                <xsl:apply-templates/>


            </fo:table-body>
        </fo:table>
       


    </xsl:template>
    <!-- row section-->
    <xsl:template match="DPROW">
   
        <fo:table-row>
       
            <xsl:apply-templates/>

        </fo:table-row>
       
    </xsl:template>
    <!--sect 5-->
    <xsl:template match="OBJECT">
        <fo:table-cell padding-start="3pt" padding-end="3pt" 
padding-before="3pt" padding-after="3pt" border-style="solid" 
border-color="black" border-width="1pt">
            <xsl:if test="@COLSPAN">
                <xsl:attribute 
name="number-columns-spanned"><xsl:value-of 
select="@COLSPAN"/></xsl:attribute>
            </xsl:if>
            <xsl:if test="@ROWSPAN">
                <xsl:attribute name="number-rows-spanned"><xsl:value-of 
select="@ROWSPAN"/></xsl:attribute>
            </xsl:if>
            <xsl:if test="@border='1' or
                    ancestor::tr[@border='1'] or
                    ancestor::thead[@border='1'] or
                    ancestor::table[@border='1']">
                <xsl:attribute 
name="border-style"><xsl:text>solid</xsl:text></xsl:attribute>
                <xsl:attribute 
name="border-color"><xsl:text>black</xsl:text></xsl:attribute>
                <xsl:attribute 
name="border-width"><xsl:text>1pt</xsl:text></xsl:attribute>
            </xsl:if>
            <xsl:variable name="align">
                <xsl:choose>
                    <xsl:when test="@ALIGN">
                        <xsl:choose>
                            <xsl:when test="@ALIGN='center'">
                                <xsl:text>center</xsl:text>
                            </xsl:when>
                            <xsl:when test="@ALIGN='left'">
                                <xsl:text>left</xsl:text>
                            </xsl:when>
                            <xsl:when test="@ALIGN='right'">
                                <xsl:text>end</xsl:text>
                            </xsl:when>
                            <xsl:when test="@ALIGN='justify'">
                                <xsl:text>justify</xsl:text>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:text>start</xsl:text>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                   
                   
                </xsl:choose>
            </xsl:variable>
            <fo:block text-align="{$align}" wrap-option="no-wrap" >
           
                <xsl:attribute 
name="font-family"><xsl:text>Courier</xsl:text></xsl:attribute>
                <xsl:attribute 
name="font-weight"><xsl:text>bold</xsl:text></xsl:attribute>
                <xsl:attribute 
name="font-size"><xsl:text>10pt</xsl:text></xsl:attribute>
               
                   
                <xsl:choose>
                <xsl:when test="text() = '&#160;'">
                    <fo:block />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates select="*|text()"/>

                </xsl:otherwise>
                </xsl:choose>
            </fo:block>
        </fo:table-cell>
    </xsl:template>
    <!--sect 6-->
   
    <!--sect 7-->
   
    <xsl:template match="title">
        <fo:block space-after="18pt" line-height="27pt" font-size="24pt" 
font-weight="bold" text-align="center">
            <xsl:apply-templates select="*|text()"/>
        </fo:block>
    </xsl:template>
</xsl:stylesheet>

Current output:

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <fo:layout-master-set>
        <fo:simple-page-master master-name="all" page-height="11in" 
page-width="8.5in" margin-left=".25in" margin-right=".25in">
            <fo:region-body region-name="all-body" margin-bottom=".55in" 
margin-top=".79in"/>
            <fo:region-before region-name="all-before" extent="1in" 
display-align="after" padding="6pt 1in"/>
            <fo:region-after region-name="all-after" extent="1in" 
display-align="before" padding="6pt 1in"/>
        </fo:simple-page-master>
    </fo:layout-master-set>
    <fo:page-sequence master-reference="all">
        <fo:flow flow-name="all-body">
            <fo:block space-after="18pt" line-height="27pt" 
font-size="24pt" font-weight="bold" text-align="center">Report1</fo:block>
            <fo:table table-layout="fixed" width="7.5in" 
space-before.optimum="5pt">
                <fo:table-column column-width="50pt"/>
                <fo:table-column column-width="6.26in"/>
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell padding-start="3pt" 
padding-end="3pt" padding-before="3pt" padding-after="3pt" 
border-style="solid" border-color="black" border-width="1pt">
                            <fo:block text-align="left" 
wrap-option="no-wrap" font-family="Courier" font-weight="bold" 
font-size="10pt"/>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
            <fo:table table-layout="fixed" width="7.5in" 
space-before.optimum="5pt">
                <fo:table-column column-width="50pt"/>
                <fo:table-column column-width="3.13in"/>
                <fo:table-column column-width="3.13in"/>
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell padding-start="3pt" 
padding-end="3pt" padding-before="3pt" padding-after="3pt" 
border-style="solid" border-color="black" border-width="1pt">
                            <fo:block text-align="left" 
wrap-option="no-wrap" font-family="Courier" font-weight="bold" 
font-size="10pt"/>
                        </fo:table-cell>
                        <fo:table-cell padding-start="3pt" 
padding-end="3pt" padding-before="3pt" padding-after="3pt" 
border-style="solid" border-color="black" border-width="1pt">
                            <fo:block text-align="start" 
wrap-option="no-wrap" font-family="Courier" font-weight="bold" 
font-size="10pt">
                                <fo:table table-layout="fixed" 
width="7.5in" space-before.optimum="5pt">
                                    <fo:table-column column-width="50pt"/>
                                    <fo:table-column 
column-width="0.0680434782608696in"/>
                                    <fo:table-column 
column-width="0.0680434782608696in"/>
                                    <fo:table-column 
column-width="0.0680434782608696in"/>
                                    <fo:table-column 
column-width="0.0680434782608696in"/>
                                    <fo:table-column 
column-width="0.0680434782608696in"/>
                                    <fo:table-column 
column-width="0.0680434782608696in"/>
                                    <fo:table-column 
column-width="0.0680434782608696in"/>
                                    <fo:table-column 
column-width="0.0680434782608696in"/>
                                    <fo:table-column 
column-width="0.0680434782608696in"/>
                                    <fo:table-column 
column-width="0.0680434782608696in"/>
                                    <fo:table-column 
column-width="0.0680434782608696in"/> <- This line repeats 300 + times 
for all the object occurences in the complete xml file



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords