Page 1 of 1

A different type of xml

Posted: Tue Jan 23, 2007 6:02 pm
by hbmehta15
I have an auto generated xml from java something like this

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.5.0_09" class="java.beans.XMLDecoder">
<object class="src.UserDetails">
<void property="firstNameDataText">
<string>Nombre (s)</string>
</void>
<void property="lastNameDataText">
<string>Apellidos</string>
</void>
<!-- Many More Fields -->
</object>
</java>



In PDF I want to use table where firstName and LastName will be in same row...
The XSL I wrote is as follows

<xsl:template match="void">

<fo:table table-layout="fixed" width="75%" border="0.2pt solid black">
<fo:table-column column-width="proportional-column-width(1)"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<xsl:if test= "@property='firstNameDataText'">
<fo:block font-size="5pt"
font-family="sans-serif"
color="black"
text-align="left">
<xsl:value-of select ="string"/>
</fo:block>
</xsl:if>
</fo:table-cell>
<fo:table-cell>
<xsl:if test= "@property='lastNameDataText'">
<fo:block font-size="5pt"
font-family="sans-serif"
color="black">
<xsl:value-of select ="string"/>
</fo:block>
</xsl:if>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</xsl:template>

The problem here i am facing is tht, it is creating table everytime it encounters void tag. But every field in my xml is identified by attribute name and not tag name.

Posted: Wed Jan 24, 2007 12:40 pm
by sorin_ristache
Hello,

Your stylesheet creates a fo:table for each void element in the XML input document. To create a fo:table for each object element and a fo:table-row for each void element you can use the following templates in your stylesheet.

Code: Select all

<xsl:template match="object">
<fo:table table-layout="fixed" border="0.2pt solid black">
<fo:table-column column-width="proportional-column-width(1)"/>
<fo:table-body>
<xsl:apply-templates select="void"/>
</fo:table-body>
</fo:table>
</xsl:template>

<xsl:template match="void">
<fo:table-row>
<fo:table-cell>
<xsl:if test= "@property='firstNameDataText'">
<fo:block font-size="5pt"
font-family="sans-serif"
color="black"
text-align="left">
<xsl:value-of select ="string"/>
</fo:block>
</xsl:if>
</fo:table-cell>
<fo:table-cell>
<xsl:if test= "@property='lastNameDataText'">
<fo:block font-size="5pt"
font-family="sans-serif"
color="black">
<xsl:value-of select ="string"/>
</fo:block>
</xsl:if>
</fo:table-cell>
</fo:table-row>
</xsl:template>
Regards,
Sorin