 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 29th, 2010, 09:40 AM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
get the point location in axis
when i draw the path in SVG, the axis(x,y) will be created automatically behind XML code.
For example: when i draw the line that connects between A and B the code will be:
<path drawme="no" d="M714.9 709.627 L 861.006 712.2919" opacity="0.1" stroke-width="10"/>
it means A(x,y)=A(714.9,709.627) and B(x,y)=B(861.006,712.2919)
So when i try to draw the zigzag line the following code will be generated:
d="M128.149 96.88 L 595.3 198.8 Q 610 202.9 624.744 199.2 L 1101.6 110.161"
It means the path crossed 4 points. But for the transformation I just need to know the starting point and the end point.
The target document will be as following code:
<line>
<startpoint x="128.149" y="96.88"/>
<endpoint x="1101.6" y="110.161"/>
</line>
-----------------
Could you please give me the best solution for this transformation
|
|

August 29th, 2010, 04:54 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Assuming you are using XPath 2.0, it's
Code:
tokenize(. '[p{L}\s]+')[position() = (1, 2, last()-1, last())]
If you're not using XPath 2.0, then you can't do it in pure XPath, it will need recursive templates.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

August 29th, 2010, 05:11 PM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
I'm using Xpath 2.0
I don't know how to deal with tokenize. BUt for my solution, I try like this and it's unsuccess with $y2. Could you modify something in my case.
<template name="aaa">
<xsl:variable name="x1" select="svg:path/substring-before(substring-after(@d,'M'),' ')"/>
<xsl:variable name="y1" select="svg:path/substring-before(substring-after(@d,' '),' L')"/>
<xsl:variable name="x2" select="svg:path/substring-before(substring-after(@d,' L '),' ')"/>
<xsl:variable name="y2" select="svg:path/substring-before(substring-after(@d,' '),'"')"/>
<points>
<startpoint x="{$x1}" y="{$y1}"/>
<endpoint x="{$x2}" y="{$y2}"/>
</points>
</template>
|
|

August 29th, 2010, 05:33 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
SVG allows any number of "M", "L", etc parts to a path. You can't find the last coordinate pair using XPath 1.0 functions such as substring-before() and substring-after(); if you're stuck with XSLT 1.0 then you'll have to use something like the EXSLT recursive str:tokenize template in place of my call on the XPath 2.0 tokenize() function. Really, you don't want to attempt this in XPath 1.0 if you can possible avoid it.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| axis problem |
asap |
XSLT |
3 |
July 31st, 2006 02:26 AM |
| y-axis |
crmpicco |
Javascript How-To |
1 |
February 3rd, 2005 08:50 AM |
| get right axis |
Kabe |
XSLT |
2 |
February 19th, 2004 12:03 PM |
| JBuilder with Axis |
Fyrosedreams |
Apache Tomcat |
0 |
August 22nd, 2003 10:26 AM |
|
 |