Hi Niko,
I think it is a problem with the context the key function is executed
in. Change the context to the main document and it should work, see below:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:svg="http://www.w3.org/2000/svg">
<xsl:output indent="yes"/>
<xsl:param name="linefactor" select="1"/>
<xsl:key name="vertex" match="coordinates" use="@id"/>
<xsl:variable name="root" select="/"/>
<xsl:template match="embedding">
<svg:svg width="3" height="3">
<xsl:apply-templates select="document('graph.xml')/graph"/>
<xsl:apply-templates select="coordinates"/>
</svg:svg>
</xsl:template>
<xsl:template match="coordinates">
<svg:circle r="{0.075*$linefactor}"
style="stroke:black; stroke-width:{0.05*$linefactor}; fill:white;"
cx="{number(double[1]/@value)+1.5}"
cy="{1.5-number(double[2]/@value)}"/>
</xsl:template>
<xsl:template match="edge">
<xsl:variable name="this" select="."/>
<xsl:for-each select="$root">
<svg:line style="stroke:black; stroke-width:{0.05*$linefactor};
fill:none;"
x1="{number(key('vertex',$this/@from)/double[1]/@value)+1.5}"
y1="{1.5-number(key('vertex',$this/@from)/double[2]/@value)}"
x2="{number(key('vertex',$this/@to)/double[1]/@value)+1.5}"
y2="{1.5-number(key('vertex',$this/@to)/double[2]/@value)}"/>
</xsl:for-each>
</xsl:template>
</xsl:transform>
Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Nico Van Cleemput wrote:
Hi,
in our application we use XSLT to construct a svg from some of our
XML-files. This worked find with java 5 until recently someone upgraded
to java 6 and it no longer works. I guess there was always something
wrong but the standard XSLT processor in Java 5 probably wasn't that
strict.
I have included the XSLT file, both the input files and the output. The
problem is of course that there appears NaN. The transform is run on
embedding.xml and document('graph') returns the graph.xml file. My guess
is that the key looks for the coordinates inside the graph.xml file
because everything works fine in the part that draws the vertices. The
desired output is of course the output in java 5.
Can anyone help me on this?
Thanks,
Nico Van Cleemput
Ghent University
XSLT:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:svg="http://www.w3.org/2000/svg">
<xsl:param name="linefactor"/>
<xsl:key name="vertex" match="coordinates" use="@id"/>
<xsl:template match="embedding">
<svg:svg width="3" height="3">
<xsl:apply-templates select="document('graph')/graph"/>
<xsl:apply-templates select="coordinates"/>
</svg:svg>
</xsl:template>
<xsl:template match="coordinates">
<svg:circle r="{0.075*$linefactor}" style="stroke:black;
stroke-width:{0.05*$linefactor}; fill:white;"
cx="{number(double[1]/@value)+1.5}" cy="{1.5-number(double[2]/@value)}"/>
</xsl:template>
<xsl:template match="edge">
<svg:line style="stroke:black; stroke-width:{0.05*$linefactor};
fill:none;" x1="{number(key('vertex',@from)/double[1]/@value)+1.5}"
y1="{1.5-number(key('vertex',@from)/double[2]/@value)}"
x2="{number(key('vertex',@to)/double[1]/@value)+1.5}"
y2="{1.5-number(key('vertex',@to)/double[2]/@value)}"/>
</xsl:template>
</xsl:transform>
EMBEDDING.XML:
<?xml version="1.0" encoding="UTF-8"?>
<embedding dimension="2">
<coordinates id="0">
<double value="-1.0" />
<double value="-1.0" />
</coordinates>
<coordinates id="1">
<double value="1.0" />
<double value="1.0" />
</coordinates>
</embedding>
GRAPH.XML:
<?xml version="1.0" encoding="UTF-8"?>
<graph nrofvertices="2">
<edge from="0" to="1" />
</graph>
OUTPUT in java 5:
<?xml version="1.0" encoding="UTF-8"?>
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="3" height="3">
<svg:line style="stroke:black; stroke-width:0.025; fill:none;"
x1="0.5" y1="2.5" x2="2.5" y2="0.5"/>
<svg:circle r="0.0375" style="stroke:black; stroke-width:0.025;
fill:white;" cx="0.5" cy="2.5"/>
<svg:circle r="0.0375" style="stroke:black; stroke-width:0.025;
fill:white;" cx="2.5" cy="0.5"/>
</svg:svg>
OUTPUT in java 6:
<?xml version="1.0" encoding="UTF-8"?>
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="3" height="3">
<svg:line style="stroke:black; stroke-width:0.025; fill:none;"
x1="NaN" y1="NaN" x2="NaN" y2="NaN"/>
<svg:circle r="0.0375" style="stroke:black; stroke-width:0.025;
fill:white;" cx="0.5" cy="2.5"/>
<svg:circle r="0.0375" style="stroke:black; stroke-width:0.025;
fill:white;" cx="2.5" cy="0.5"/>
</svg:svg>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--