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 April 4th, 2007, 08:14 AM
Authorized User
 
Join Date: Jul 2006
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok,my new code is as follows.I dont get any error now but the result string is an empty string what is impossible because "//situation" could never fail.
I'm certainly loading saxon now.

Any ideas?

String result = null;
        //String xpathExpressionStr = "max(//situation/situationRecord/situationRecordVersionTime/xs:dateTime(.) )";
        String xpathExpressionStr = "//situation";

        try
        {

            XPath xpath = new net.sf.saxon.xpath.XPathEvaluator();

            XPathExpression xpathExpression = xpath.compile(xpathExpressionStr);

            result = xpathExpression.evaluate(new InputSource(new StringReader(xml)));

            System.out.println("RESULT: "+ result);

        }
        catch(Exception e)
        {
            System.out.println("Error Eval(): "+ e.getMessage());
        }
        return result;

 
Old April 4th, 2007, 09:17 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If //situation selects a set of nodes, then the way you are calling evaluate() that node-set will be converted to a string, which under the XPath 1.0 rules will give you the string value of the first element in the set. In the XML you showed us earlier, the string value of the situation element is an empty string.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 4th, 2007, 10:26 AM
Authorized User
 
Join Date: Jul 2006
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>

<d2LogicalModel xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:d2lm="D2LogicalModel" xmlns="http://datex2.eu/schema/1_0/1_0" modelBaseVersion="1.0" xsi:schemaLocation="http://datex2.eu/schema/1_0/1_0>
    <exchange>
        <supplierIdentification>
            <country>oiss</country>
            <nationalIdentifier>oiss001</nationalIdentifier>
        </supplierIdentification>
    </exchange>
    <payloadPublication xsi:type="SituationPublication" lang="es">
        <publicationTime>2007-03-12T15:20:00+01:00</publicationTime>
        <publicationCreator>
            <country>es</country>
            <nationalIdentifier>es001</nationalIdentifier>
        </publicationCreator>
        <situation id="GUID247153">
            <headerInformation>
                <confidentiality>noRestriction</confidentiality>
                <informationStatus>real</informationStatus>
            </headerInformation>
            <situationRecord xsi:type="MaintenanceWorks" id="GUID247153_3O">
                <situationRecordCreationTime>2006-02-06T11:22:00+01:00</situationRecordCreationTime>
                <situationRecordVersion>2</situationRecordVersion>
                <situationRecordVersionTime>2006-03-06T11:22:00+01:00</situationRecordVersionTime>
                <situationRecordFirstSupplierVersionTime>2006-02-06T11:22:00+01:00</situationRecordFirstSupplierVersionTime>
                <probabilityOfOccurrence>certain</probabilityOfOccurrence>
                <validity>
                    <validityStatus>active</validityStatus>
                    <validityTimeSpecification>
                        <overallStartTime>2006-10-17T14:00:00+02:00</overallStartTime>
                        <overallEndTime>2006-10-17T16:00:00+02:00</overallEndTime>
                    </validityTimeSpecification>
                </validity>
                <groupOfLocations>
                    <locationContainedInGroup xsi:type="Linear">
                        <alertCLinear xsi:type="aaa">
                            <alertCLocationCountryCode>W</alertCLocationCountryCode>
                            <alertCLocationTableNumber>0007</alertCLocationTableNumber>
                            <alertCLocationTableVersion>0000</alertCLocationTableVersion>
                            <alertCDirection>
                                <alertCDirectionCoded>both</alertCDirectionCoded>
                            </alertCDirection>
                            <alertCMethod4PrimaryPointLocation>
                                <alertCLocation>
                                    <specificLocation>62017</specificLocation>
                                </alertCLocation>
                                <offsetDistance>
                                    <offsetDistance>000987</offsetDistance>
                                </offsetDistance>
                            </alertCMethod4PrimaryPointLocation>
                            <alertCMethod4SecondaryPointLocation>
                                <alertCLocation>
                                    <specificLocation>62019</specificLocation>
                                </alertCLocation>
                                <offsetDistance>
                                    <offsetDistance>00098</offsetDistance>
                                </offsetDistance>
                            </alertCMethod4SecondaryPointLocation>
                        </alertCLinear>
                    </locationContainedInGroup>
                </groupOfLocations>
                <effectOnRoadLayout>roadLayoutUnchanged</effectOnRoadLayout>
                <roadMaintenanceType>roadworks</roadMaintenanceType>
            </situationRecord>
            <situationRecord xsi:type="NetworkManagement" id="GUID247153_1O">
                <situationRecordCreationTime>2006-02-06T12:22:00+01:00</situationRecordCreationTime>
                <situationRecordVersion>2</situationRecordVersion>
                <situationRecordVersionTime>2006-02-06T12:22:00+01:00</situationRecordVersionTime>
                <situationRecordFirstSupplierVersionTime>2006-02-06T11:22:00+01:00</situationRecordFirstSupplierVersionTime>
                <probabilityOfOccurrence>certain</probabilityOfOccurrence>
                <validity>
                    <validityStatus>active</validityStatus>
                    <validityTimeSpecification>
                        <overallStartTime>2006-10-17T14:00:00+02:00</overallStartTime>
                        <overallEndTime>2006-10-17T16:00:00+02:00</overallEndTime>
                    </validityTimeSpecification>
                </validity>
                <groupOfLocations>
                    <locationContainedInGroup xsi:type="Linear">
                        <alertCLinear xsi:type="AlertCMethod4Linear">
                            <alertCLocationCountryCode>E</alertCLocationCountryCode>
                            <alertCLocationTableNumber>17</alertCLocationTableNumber>
                            <alertCLocationTableVersion>2.0</alertCLocationTableVersion>
                            <alertCDirection>
                                <alertCDirectionCoded>both</alertCDirectionCoded>
                            </alertCDirection>
                            <alertCMethod4PrimaryPointLocation>
                                <alertCLocation>
                                    <specificLocation>62017</specificLocation>
                                </alertCLocation>
                                <offsetDistance>
                                    <offsetDistance>1650</offsetDistance>
                                </offsetDistance>
                            </alertCMethod4PrimaryPointLocation>
                            <alertCMethod4SecondaryPointLocation>
                                <alertCLocation>
                                    <specificLocation>62019</specificLocation>
                                </alertCLocation>
                                <offsetDistance>
                                    <offsetDistance>1650</offsetDistance>
                                </offsetDistance>
                            </alertCMethod4SecondaryPointLocation>
                        </alertCLinear>
                    </locationContainedInGroup>
                </groupOfLocations>
                <networkManagementType>restrictions</networkManagementType>
            </situationRecord>
        </situation>
    </payloadPublication>
</d2LogicalModel>


I want to select the latest date of the <situationRecordVersionTime> tag.Ive used the following query "max(//situation/situationRecord/situationRecordVersionTime/xs:dateTime(.))" and It also returns an empty string.Could you please help me with this query.

I think this query should not return a set of nodes.

THANKS!!

 
Old April 4th, 2007, 11:16 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your nodes are in a namespace: xmlns="http://datex2.eu/schema/1_0/1_0". Your XPath expression will only find them if it looks for them in this namespace, which is achieved by binding a prefix to the namespace and writing //p:situation.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 5th, 2007, 02:07 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I refer you to this thread, started by someone named Tomi. What exactly is it about default namespaces that you are not grasping?

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
retrieving comma separated values from column abhishekkashyap27 SQL Server 2005 6 April 21st, 2008 09:27 AM
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
values comparison in xsl sani723 XSLT 2 April 3rd, 2007 04:05 AM
delay in retrieving values through session mrjoka ASP.NET 2.0 Basics 2 March 14th, 2007 08:02 AM
Need help in retrieving values from a loop ! back2grave XSLT 0 June 27th, 2006 05:29 PM





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