Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old August 29th, 2010, 09:40 AM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default 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
 
Old August 29th, 2010, 04:54 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old August 29th, 2010, 05:11 PM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default 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,' '),'&quot;')"/>
<points>
<startpoint x="{$x1}" y="{$y1}"/>
<endpoint x="{$x2}" y="{$y2}"/>
</points>
</template>
 
Old August 29th, 2010, 05:33 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.