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 May 8th, 2008, 11:40 PM
Registered User
 
Join Date: May 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default XPath Conditionals

The below code works fine:
Code:
    <xsl:variable name="Months">
       <i ref="Jan" val="01">01</i>
       <i ref="Feb" val="02">02</i>
       ...
     </xsl:variable>

     <xsl:sort order="descending" select="
         concat(
         substring(@created, 13, 4 ),
         document('')/*/xsl:variable[@name='Months']/i[@ref=substring(current()/@created, 9, 3 )]/@val,
         substring(@created, 6, 2 ),
         substring(@created, 18, 8 )
         ) ) />
But when I surround the sort selection with a conditional as I am certain is allowed, at the sort instruction, the processor gives me an "F Error in expression" and "E error in expression" and I don't understand why.

Code:
     ...
     <xsl:param name="sortBy" select="created" as="xs:string"/>
     <xsl:sort order="descending" select="
       if($sortBy='created') then (
         concat(
         substring(@created, 13, 4 ),
         document('')/*/xsl:variable[@name='Months']/i[@ref=substring(current()/@created, 9, 3 )]/@val,
         substring(@created, 6, 2 ),
         substring(@created, 18, 8 )
         ) )
       else
         ( concat(
         substring(@modified, 13, 4 ),
         document('')/*/xsl:variable[@name='Months']/i[@ref=substring(current()/@modified, 9, 3 )]/@val,
         substring(@modified, 6, 2 ),
         substring(@modified, 18, 8 )
         ) )
       " />
Any help would be greatly appreciated. Thanks!

Jeff

Headers:
Code:
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
  xmlns:xs="http://www.w3.org/2001/XMLSchema"  
  xmlns:xdt="http://www.w3.org/2005/04/xpath-datatypes"  
  version="2.0">
--

Check out my blog, http://www.tipninja.com, the where I share tips from optimizing your PC use, to cooking and food storage and household organization to personal happiness.
 
Old May 9th, 2008, 03:00 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I would think the most likely explanation is that you have tried to run this under an XSLT 1.0 processor. Conditionals in XPath expressions require 2.0.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 9th, 2008, 10:50 PM
Registered User
 
Join Date: May 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You were right. Thanks very much Michael!

Jeff Axelrod





Similar Threads
Thread Thread Starter Forum Replies Last Post
XPATH pallone XSLT 4 March 3rd, 2008 10:58 AM
Xpath help please rishid XML 1 February 28th, 2007 03:23 AM
XPath help migake XSLT 2 April 21st, 2006 10:49 AM
Xpath Ma7T XSLT 2 August 16th, 2005 07:54 AM
XPath rupen XML 2 April 19th, 2005 09:43 AM





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