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 8th, 2011, 11:22 AM
Authorized User
 
Join Date: Feb 2007
Posts: 51
Thanks: 3
Thanked 0 Times in 0 Posts
Default Querying Data Field Against Data Value

Hello,

In the below code fragment, I have a need to build an expression that can determine (as an example) if velocity is > 0. The DataArray fields relate to the comma-delimited ns1:values element directly. As an example, since the 5th array element is "velocity", the 5th value in the ns1:values (0.0) is the value of the velocity. By the way, I cannot assume that velocity is always the 5th value.

My question: can an expression be built that compares a DataArray field to its corresponding value in ns1:values? If so, would anyone be able to provide me with some guidance on how this would be done? Thanks for any response!

Code:
                          <ns1:DataArray xmlns:ns1="http://www.opengis.net/swe/1.0.1">
                                <ns1:elementCount>
                                    <ns1:Count>
                                    <ns1:value>1</ns1:value>
                                    </ns1:Count>
                                </ns1:elementCount>
                                <ns1:elementType name="Components">
                                    <ns:DataRecord xmlns:ns="http://www.opengis.net/swe/1.0.1">
                                    <ns:field name="Time">
                                    <ns:Time definition="urn:ogc:data:time:iso8601"/>
                                    </ns:field>
                                    <ns:field name="feature">
                                    <ns:Text definition="urn:ogc:data:feature"/>
                                    </ns:field>
                                    <ns:field name="position">
                                    <ns:Position definition="urn:ogc:def:property:OGC:1.0.30:position"/>
                                    </ns:field>
                                    <ns:field name="altitude">
                                    <ns:Quantity definition="urn:ogc:def:phenomenon:OGC:1.0.30:altitude">
                                    <ns:uom code="m"/>
                                    </ns:Quantity>
                                    </ns:field>
                                    <ns:field name="velocity">
                                    <ns:Quantity definition="urn:ogc:def:phenomenon:OGC:1.0.30:velocity">
                                    <ns:uom code="m/h"/>
                                    </ns:Quantity>
                                    </ns:field>
                                    <ns:field name="heading">
                                    <ns:Quantity definition="urn:ogc:def:phenomenon:OGC:1.0.30:heading">
                                    <ns:uom code="deg"/>
                                    </ns:Quantity>
                                    </ns:field>
                                    <ns:field name="source">
                                    <ns:Category definition="urn:ogc:def:phenomenon:OGC:1.0.30:source"/>
                                    </ns:field>
                                    <ns:field name="destination">
                                    <ns:Category definition="urn:ogc:def:phenomenon:OGC:1.0.30:destination"/>
                                    </ns:field>
                                    <ns:field name="target">
                                    <ns:Category definition="urn:ogc:def:phenomenon:OGC:1.0.30:target"/>
                                    </ns:field>
                                    <ns:field name="symbol">
                                    <ns:Category definition="urn:ogc:def:phenomenon:OGC:1.0.30:symbol"/>
                                    </ns:field>
                                    <ns:field name="symboltable">
                                    <ns:Category definition="urn:ogc:def:phenomenon:OGC:1.0.30:symboltable"/>
                                    </ns:field>
                                    </ns:DataRecord>
                                </ns1:elementType>
                                <ns1:encoding>
                                    <ns1:TextBlock blockSeparator=";"
                                    decimalSeparator="." tokenSeparator=","/>
                                </ns1:encoding>
                                <ns1:values>2011-03-30T15:35:41.638Z,aprs-w4brm-1,POINT(38.92216666666667 -77.66333333333333)#4326,0.0,0.0,0,w4brm-1,APRS,,r,/;</ns1:values>
                            </ns1:DataArray>
 
Old April 8th, 2011, 11:36 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Do you use XSLT 2.0 or 1.0? With XSLT 2.0 you could easily tokenize the comma separated list in ns1: values e.g.
Code:
<xsl:variable name="values" select="tokenize(ns1:values, ',')"/>
then you can select the position of the velocity field and index the values variable e.g.
Code:
<xsl:variable name="pos" select="count(ns1:elementType/ns:DataRecord/ns:field[@name = 'velocity']/preceding-sibling::ns:field) + 1"/>
<xsl:variable name="velocity" select="$values[$pos]"/>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old April 8th, 2011, 12:41 PM
Authorized User
 
Join Date: Feb 2007
Posts: 51
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thanks for reply. I should have clarified. I must use XSLT 1.0. Any reasonable way to do it in 1.0? Thanks for any reply!
 
Old April 8th, 2011, 12:52 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Check whether your XSLT 1.0 processor supports http://www.exslt.org/str/functions/tokenize/index.html, then you can use the same approach, only instead of the XPath 2.0 tokenize function you use the EXSLT one.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old April 8th, 2011, 02:05 PM
Authorized User
 
Join Date: Feb 2007
Posts: 51
Thanks: 3
Thanked 0 Times in 0 Posts
Default

thanks for reply.. Hmm, I should clarify that these expressions have to be written as xpath (the tool I am relying on contains an xpath processor to which I pass xpath-based expressions).

The code sample I gave is an example of a sensor notification the xpath processor would process my xpath expression against. Unfortunately, I do not know how to determine whether the xpath expression can properly process the tokenizer you mention.

Is it possible to simply assume that it doesn't support that tokenizer (I know it is not 2.0 compliant in general), and someone help me define an xpath expression that would work?

Again, any reply appreciated. Thanks for your responses!
 
Old April 9th, 2011, 07:26 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I doubt it is possible with pure XPath 1.0 to find the right substring if you don't know its position but need to compute that too.
If you know the position then you need to use substring-before/after often enough to extract the right substring e.g.
Code:
substring-before(substring-after(substring-after(substring-after(substring-after(ns1:values, ','), ','), ','), ','), ',')
should find the fifth substring.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
tclotworthy (April 9th, 2011)
 
Old April 9th, 2011, 01:21 PM
Authorized User
 
Join Date: Feb 2007
Posts: 51
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thank you Martin. I appreciate your help. I will get by with this for now.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Querying XML data jtnchang ASP.NET 3.5 Professionals 8 January 29th, 2010 07:14 AM
Stripping Data from a Field jjc9809 Access VBA 1 July 12th, 2008 08:16 PM
Merging Data in a Field MichelleArmstrong Access 2 November 21st, 2007 07:48 AM
Data not fitting into field v4seasons SQL Server 2000 2 October 13th, 2007 05:55 AM
Data field limits rayncarnation Access 1 October 15th, 2005 02:27 PM





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