xsl-list
[Top] [All Lists]

RE: [xsl] Ways to simplify XSL, complex "select/filter criteria"

2010-01-07 12:57:55

I tried the transformation in Altova. It complains about Error in XPath 2.0 
expression
Cast failed, invalid lexical value - '2005-09-19T00:00:00
                 ...

             ...
2010-09-19T00:00:00email1(_at_)my(_dot_)com2010-09-19T00:00:00email2(_at_)my(_dot_)com'

If I change '2005-09-19T00:00:00' to 2005-09-19. The same error. Do you know 
why?


----------------------------------------
From: mike(_at_)saxonica(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Date: Fri, 18 Dec 2009 10:23:36 +0000
Subject: RE: [xsl] Ways to simplify XSL, complex "select/filter criteria"


I don't think I fully understand the requirement, but it's certainly a case
where your code can be simplified by use of functions. For example you can
define this function




select="xs:dateTime($v/ns:startDateTime)"/>

select="xs:dateTime($v/ns:endDateTime)"/>



and this one






and then you can do things like


[exists(ns:validFor[f:applies-now(.)])]"/>

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay

-----Original Message-----
From: Stefan Fritz [mailto:sfritz(_dot_)nospam(_at_)gmx(_dot_)at]
Sent: 18 December 2009 10:07
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Ways to simplify XSL, complex "select/filter criteria"

Hi all,

first my environment: Saxon 8.9, XSL and Xpath 2.0, Java

I have to transform a XML document which contains elements
with the same name but different xs:type.
In addition the elements contain an optional validFor element
which defines a time period for the validity of the data.

The rules to implement is:
- select element by xsi type
- select the valid (in time period) element
- if no time period specified and multiple elements of the
same type exist, take the first one

I have to apply these rules in almost every value-of
selection in my XSLT and therefore the XSLT became really a nightmare.
I hope there is a solution to simplify this. I though about
xsl:function, dynamic Xpath (saxon:evaluate,..) but couldn't
get it to work.
Any help more than appreciated!

Thanks
Stefan

simplified XML and XSL:


xsi:type="ns:Individual"
xmlns:ns="http://myns";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>


1800-01-01T00:00:00





2005-09-19T00:00:00



...


...



2010-09-19T00:00:00

email1(_at_)my(_dot_)com



2010-09-19T00:00:00

email2(_at_)my(_dot_)com







xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:cdm="http://myns";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>




select="/cdm:Individual/cdm:PartyPlays[contains(@xsi:type,'Emp
loyee')][
if(string-length(cdm:validFor/cdm:startDateTime) gt 0 and
string-length(cdm:validFor/cdm:endDateTime) gt 0) then
(xs:dateTime(cdm:validFor/cdm:startDateTime) lt
current-dateTime() and
xs:dateTime(cdm:validFor/cdm:endDateTime)gt
current-dateTime()) else
if(string-length(cdm:validFor/cdm:startDateTime) gt 0) then
(xs:dateTime(cdm:validFor/cdm:startDateTime) lt
current-dateTime()) else
if(string-length(cdm:validFor/cdm:endDateTime) gt 0) then (
xs:dateTime(cdm:validFor/cdm:endDateTime)gt current-dateTime()) else
1
]/cdm:PartyRoleContactableVia[contains(@xsi:type,'EMailContact')][
if(string-length(cdm:validFor/cdm:startDateTime) gt 0 and
string-length(cdm:validFor/cdm:endDateTime) gt 0) then
(xs:dateTime(cdm:validFor/cdm:startDateTime) lt
current-dateTime() and
xs:dateTime(cdm:validFor/cdm:endDateTime)gt
current-dateTime()) else
if(string-length(cdm:validFor/cdm:startDateTime) gt 0) then
(xs:dateTime(cdm:validFor/cdm:startDateTime) lt
current-dateTime()) else
if(string-length(cdm:validFor/cdm:endDateTime) gt 0) then (
xs:dateTime(cdm:validFor/cdm:endDateTime)gt current-dateTime()) else
1
][1]/cdm:eMailAddress[1]"/>





--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
--~--



--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
--~--

                                          
_________________________________________________________________
Hotmail: Trusted email with powerful SPAM protection.
http://clk.atdmt.com/GBL/go/196390707/direct/01/
--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>