I am relatively new to XSLT, but I have a problem which seems very strange to me and I hope you will be able to help me out.
I have an xml file which contains information about the x and y sizes of sheets in a document and x and y size of the bitmap projected on that sheet.
<apv>
<sheet>
...
<attr name="Sheet size x">2159</attr>
<attr name="Sheet size y">2794</attr>
<attr name="Front bitmap x size">6624</attr>
<attr name="Front bitmap y size">5100</attr>
<attr name="Rear bitmap x size">6624</attr>
<attr name="Rear bitmap y size">5100</attr>
...
</sheet>
</apv>
Now I want to transform this XML into a PDF file which contains svg images which give a view of the sheets and the bitmap of the sheets. I use fop 0.95 in a Java application to construct the PDF file from the given XML and XSL files.
The important part of my XSL file looks like this (I already stepped into apv/sheet):
<!-- Sheet Variables -->
<xsl:variable name="sheet_width">
<xsl:for-each select="attr">
<xsl:if test="@name = 'Sheet size x'">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="sheet_height">
<xsl:for-each select="attr">
<xsl:if test="@name = 'Sheet size y'">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="proportion" select="$sheet_width div $sheet_height"/>
<xsl:variable name="svg_height">
350
</xsl:variable>
<xsl:variable name="svg_width" select="$proportion * $svg_height"/>
<!-- Front Bitmap Variables -->
<xsl:variable name="front_bitmap_width">
<xsl:for-each select="attr">
<xsl:if test="@name = 'Front bitmap y size'">
<xsl:value-of select="(. div $horizontal_dpi) * 254"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="front_bitmap_height">
<xsl:for-each select="attr">
<xsl:if test="@name = 'Front bitmap x size'">
<xsl:value-of select="(. div $vertical_dpi) * 254"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="svg_front_bitmap_width" select="($front_bitmap_width div $sheet_width) * $svg_width"/>
<xsl:variable name="svg_front_bitmap_height">
<xsl:choose>
<xsl:when test="$front_bitmap_height > $sheet_height">
<xsl:value-of select="$svg_height"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="($front_bitmap_height div $sheet_height) * $svg_height"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Rear Bitmap Variables -->
<xsl:variable name="rear_bitmap_width">
<xsl:for-each select="attr">
<xsl:if test="@name = 'Rear bitmap y size'">
<xsl:value-of select="(. div $horizontal_dpi) * 254"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="rear_bitmap_height">
<xsl:for-each select="attr">
<xsl:if test="@name = 'Rear bitmap x size'">
<xsl:value-of select="(. div $vertical_dpi) * 254"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="svg_rear_bitmap_width" select="($rear_bitmap_width div $sheet_width) * $svg_width"/>
<xsl:variable name="svg_rear_bitmap_height">
<xsl:choose>
<xsl:when test="$rear_bitmap_height > $sheet_height">
<xsl:value-of select="$svg_height"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="($rear_bitmap_height div $sheet_height) * $svg_height"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
...
<fo:instream-foreign-object>
<svg:svg width="{$svg_width}" height="{$svg_height}">
<!-- Draw Rectangle of Sheet -->
<svg:rect width="{$svg_width}" height="{$svg_height}" style="fill:none; stroke-width:3; stroke:rgb(0,0,0)"/>
<!-- Draw Rectangle of Front Bitmap -->
<svg:rect width="{$svg_front_bitmap_width}" height="{$svg_front_bitmap_height}" style="fill:none; stroke-width:2; stroke:rgb(255,0,0)"/>
</svg:svg>
</fo:instream-foreign-object>
...
<fo:instream-foreign-object>
<svg:svg width="{$svg_width}" height="{$svg_height}" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Draw Rectangle of Sheet -->
<svg:rect width="{$svg_width}" height="{$svg_height}" style="fill:none; stroke-width:3; stroke:rgb(0,0,0)"/>
<!-- Draw Rectangle of Rear Bitmap -->
<svg:rect width="{$svg_rear_bitmap_width}" height="{$svg_rear_bitmap_height}" style="fill:none; stroke-width:2; stroke:rgb(255,0,0)"/>
</svg:svg>
</fo:instream-foreign-object>
...
Now my problem:
When I run the program with this XSL file I get the following error:
SEVERE: svg graphic could not be built: file:/G:/NetBeansProjects/apv2pdf:-1
The attribute "height" of the element <rect> is invalid
org.apache.batik.bridge.BridgeException: file:/G:/NetBeansProjects/apv2pdf:-1
The attribute "height" of the element <rect> is invalid
at org.apache.batik.bridge.SVGRectElementBridge.buildShape(Unknown Source)
...
The odd thing is that the program worked fine when I only had the front side of the sheet in the XSL file. Now when I replace the $svg_rear_bitmap_width and $svg_rear_bitmap_height (which both have a similar error) with the similar variables for the front it works fine. Also when I replace the variables with a fixed value it works fine. So I suspected the error is in the variables.
After that I tried replacing the variables with a fixed value and the program works fine.
I studied the code for some hours now but I can't really find a difference why everything for the front side of the sheet sheet is fine but doesn't for the rear side. Or I did something wrong completely but somehow works for the front side, then I like to know what the correct way to solve my problem is. Or there is something in the rear side variables wrong that I don't see anymore.
I hope you can help.
Thanks in advance,
Miepmuts