[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: probably a XPath mistake

Subject: RE: probably a XPath mistake
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 30 Jan 2007 08:58:45 -0000
RE:  probably a XPath mistake
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.VanCleemput@xxxxxxxx] 
> Sent: 30 January 2007 07:46
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.