This does look as if the JDK 5 processor had a pretty nasty bug.
The code seems to be written on the assumption that
key('vertex',@from)
will select data from EMBEDDING.XML; but the context node at the time is in
GRAPH.XML, so that is where the key should search. I'm afraid the fix for
this in XSLT 1.0 is tedious: my advice, since you're switching processors
anyway, would be to switch to XSLT 2.0 and Saxon, where you can write
key('vertex', @from, $embedding)
having declared the global variable:
<xsl:variable name="embedding" select="/"/>
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: Nico Van Cleemput
[mailto:Nicolas(_dot_)VanCleemput(_at_)UGent(_dot_)be]
Sent: 30 January 2007 07:46
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] probably a XPath mistake
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>
--~--