 |
| 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
|
|
|
|

October 31st, 2013, 03:52 PM
|
|
Authorized User
|
|
Join Date: Jun 2013
Posts: 13
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Migrate to XSLT 2.0 from 1.0
First off I apologize for knowing enough about xslt programming to probably be dangerous. That said, I continue to get many errors with 1.0, because apparently many functions (like Min, Max, Avg) are not available in 1.0. Thus I wish to consider moving to 2.0. What all would be involved in this? Thanks much for any advise or reference.
Jake
I'm running Win7, 64bit. Here's a sample of my .xsl.
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:template match="/MissionProfile">
<html>
<h2>Here's your Dead Reckoning course variation in decimiles:</h2>
<body>
<xsl:for-each select="Gather/Stat">
<xsl:text>Number of course samples = </xsl:text>
<xsl:value-of select="count(Point)"/>
</xsl:for-each>
<br/>
<xsl:for-each select="Gather/Stat">
<xsl:text>Average course variation = </xsl:text>
<xsl:value-of select="sum(Point)"/>
</xsl:for-each>
<xsl:text> Decimiles </xsl:text>
<br/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|
|

October 31st, 2013, 05:08 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
The vast majority of XSLT 1.0 stylesheets can be run under a 2.0 processor with no problems.
XSLT 2.0 processors have two modes, normal mode and 1.0 backwards compatibility mode. Backwards compatibility mode is active if the stylesheet specifies version="1.0". To some people's surprise, this does NOT stop you using 2.0 features such as the max() and min() functions. With backwards compatibility mode, transition problems are extremely unlikely; with 2.0 mode you might have to make a few changes, for example xsl:value-of when you select a set of nodes will show all the nodes, not only the first as in 1.0. My advice would be to move straight to 2.0 mode if you have sufficient test material to discover any such problems, but to stick with 1.0 mode if you have no test material or if you are simply more risk-averse.
There are detailed lists of incompatibilities in the XPath 2.0 and XSLT 2.0 specs, but they aren't really much use unless you know you stylesheet code extremely well, which would be unusual. Trial and error is a more common approach.
Some people find that the main effort in transition is not because of the change in language level from 1.0 to 2.0, but because of the change in processor. You may find that you were reliant on vendor extensions that are not supported by your 2.0 processor. If that's the case, you will have no choice but to fix the code (usually the vendor extension is something that's available as standard in 2.0, for example producing multiple output documents.)
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

October 31st, 2013, 05:15 PM
|
|
Authorized User
|
|
Join Date: Jun 2013
Posts: 13
Thanks: 0
Thanked 1 Time in 1 Post
|
|
OK, thanks for that but I'm now only more confused! How exactly to I declare 2.0 so that I can use the min function? Do I need to download software? What? Thanks for your help.
|
|

October 31st, 2013, 06:01 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Oh dear, sorry, I was assuming too much knowledge.
The chances are that the XSLT processor you are currently using does not support XSLT 2.0. You've told us you're running Windows, but you haven't said how you are currently running your XSLT transformations, so we don't know what XSLT processor you are using.
To use XSLT 2.0 you will need to install an XSLT 2.0 processor, that is, a piece of software that understands the syntax of the XSLT 2.0 language and is capable of interpreting it or compiling it. The one to choose depends on your processing environment, e.g. client side or server side, Java or .NET. If you are looking for a free processor that isn't part of a larger product, the main choices are Saxon, Altova, and XMLPrime. There are some environments where it's still quite tricky to get XSLT 2.0 installed, for example PHP. If you're running in the browser, you can use the new Saxon-CE product.
You don't need to change anything in your stylesheet in principle, unless there are compatibility issues as I discussed in my previous answer.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
 |