Subject: Re: [xsl] Ways to simplify XSL, complex "select/filter criteria" From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx> Date: Fri, 08 Jan 2010 01:54:06 +0100 |
Input xml was from Stefan Fritz's original post. The apostrophe is closed properly actually in the error message. Maybe Mr. Stefan Fritz can shed some light on this and share if he made the following xsl work. I'm using Altova.
Thanks.
[ Error in XPath 2.0 expression Cast failed, invalid lexical value - '2005-09-19T00:00:00 ...
... 2010-09-19T00:00:00email1@xxxxxxxxxxxxxxxxxxx:00:00email2@xxxxxx'
]
input:
<ns:Individual xsi:type="ns:Individual" xmlns:ns="http://myns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ns:validFor xsi:type="ns:TimePeriod"> <ns:startDateTime>1800-01-01T00:00:00</ns:startDateTime> <ns:endDateTime/> </ns:validFor> <ns:PartyPlays xsi:type="ns:Employee"> <ns:validFor xsi:type="ns:TimePeriod"> <ns:startDateTime>2005-09-19T00:00:00</ns:startDateTime> <ns:endDateTime/> </ns:validFor> <ns:PartyRoleContactableVia xsi:type="ns:PostalContact"> ... </ns:PartyRoleContactableVia> <ns:PartyRoleContactableVia xsi:type="ns:PostalContact"> ... </ns:PartyRoleContactableVia> <ns:PartyRoleContactableVia xsi:type="ns:EMailContact"> <ns:validFor xsi:type="ns:TimePeriod"> <ns:endDateTime>2010-09-19T00:00:00</ns:endDateTime> </ns:validFor> <ns:eMailAddress>email1@xxxxxx</ns:eMailAddress> </ns:PartyRoleContactableVia> <ns:PartyRoleContactableVia xsi:type="ns:EMailContact"> <ns:validFor xsi:type="ns:TimePeriod"> <ns:endDateTime>2010-09-19T00:00:00</ns:endDateTime> </ns:validFor> <ns:eMailAddress>email2@xxxxxx</ns:eMailAddress> </ns:PartyRoleContactableVia> </ns:PartyPlays> </ns:Individual>
xsl:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cdm="http://myns" xmlns:f="urn:f" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:value-of select="/cdm:Individual/cdm:PartyPlays[f:type(.) eq xs:QName('fn:Employee')] [exists(cdm:validFor[f:applies-now(.)])]"/> </xsl:template> <xsl:function name="f:applies-now" as="xs:boolean"> <xsl:param name="v" as="element(cdm:validFor)"/> <xsl:variable name="start" as="xs:dateTime?" select="xs:dateTime($v/cdm:startDateTime)"/> <xsl:variable name="end" as="xs:dateTime?" select="xs:dateTime($v/cdm:endDateTime)"/> <xsl:sequence select="(empty($start) or $start le current-dateTime()) and (empty($end) or $end ge current-dateTime())"/> </xsl:function> <xsl:function name="f:type" as="xs:QName"> <xsl:param name="e" as="element()"/> <xsl:sequence select="QName($e/@xsi:type, $e)"/> </xsl:function> </xsl:stylesheet>
----------------------------------------_________________________________________________________________From: mike@xxxxxxxxxxxx To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Date: Thu, 7 Jan 2010 22:08:06 +0000 Subject: RE: [xsl] Ways to simplify XSL, complex "select/filter criteria"
You'll have to give more context - I don't exactly remember this thread from a previous decade ;-)
The apostrophe in the error message looks suspicious
invalid lexical value - '2005-09-19T00:00:00
Perhaps it's present in your data?
Regards,
Michael Kay http://www.saxonica.com/ http://twitter.com/michaelhkay
-----Original Message----- From: J L [mailto:jinlii@xxxxxxxxxxx] Sent: 07 January 2010 18:57 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] Ways to simplify XSL, complex "select/filter criteria"
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@xxxxxxxxxxxxxxxxxxx:00:00email2@xxxxxx'
If I change '2005-09-19T00:00:00' to 2005-09-19. The same error. Do you know why?
----------------------------------------"select/filter criteria"From: mike@xxxxxxxxxxxx To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Date: Fri, 18 Dec 2009 10:23:36 +0000 Subject: RE: [xsl] Ways to simplify XSL, complexcertainly a
I don't think I fully understand the requirement, but it's"select/filter criteria"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.nospam@xxxxxx] Sent: 18 December 2009 10:07 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Ways to simplify XSL, complexwith theHi all,
first my environment: Saxon 8.9, XSL and Xpath 2.0, Java
I have to transform a XML document which contains elementselement whichsame name but different xs:type. In addition the elements contain an optional validForsame typedefines 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 theselection in myexist, take the first one
I have to apply these rules in almost every value-ofcouldn't get itXSLT 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,..) butcurrent-dateTime()) elseto 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@xxxxxx
2010-09-19T00:00:00
email2@xxxxxx
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)gtcurrent-dateTime()) else1 ]/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)gt1 ][1]/cdm:eMailAddress[1]"/>
_________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/196390707/direct/01/
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
http://clk.atdmt.com/GBL/go/196390709/direct/01/
-- Gerrit Imsieke Geschdftsf|hrer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke@xxxxxxxxx, http://www.le-tex.de
Registergericht / Commercial Register: Amtsgericht Leipzig Registernummer / Registration Number: HRB 24930
Geschdftsf|hrer: Gerrit Imsieke, Svea Jelonek, Thomas Schmidt, Dr. Reinhard Vvckler
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Ways to simplify XSL, com, J L | Thread | [xsl] [Announce] Upcoming hands-on , G. Ken Holman |
RE: [xsl] Ways to simplify XSL, com, J L | Date | [xsl] Enabling extension to countin, Eliot Kimber |
Month |