XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Sean SymesSubject: Xpath predicate numeric vs string help...
Author: Sean Symes
Date: 12 Jul 2005 06:36 AM
Hi all,
I've got a problem using predicates when searching on values of elements. In short the xpath statement below works if the value of an element in the predicate part is numeric, if however I change the value of the element to a string it doesn't work.
See the two code snippets below;
----- WORKS -----
XML (element value is 3)
<loop name="Party Identification">
<segment name="Name and Address">
<element ref_des="NAD01">
3
</element>
<element ref_des="NAD03">
Hello world
</element>
.... other elements I want to get data from

XSL
<xsl:value-of select="//loop[@name='Party Identification']/segment[element[@ref_des='NAD01']=3]/element[@ref_des='NAD03']"/>

----- FAILS -----
XML (element value is 'ABC')
<loop name="Party Identification">
<segment name="Name and Address">
<element ref_des="NAD01">
ABC
</element>
<element ref_des="NAD03">
Hello world
</element>
.... other elements I want to get data from

XSL
<xsl:value-of select="//loop[@name='Party Identification']/segment[element[@ref_des='NAD01']='ABC']/element[@ref_des='NAD03']"/>

Any help welcome.
Sean.

Postnext
Ivan PedruzziSubject: Xpath predicate numeric vs string help...
Author: Ivan Pedruzzi
Date: 12 Jul 2005 09:23 PM
Sean,

The second expression should work.

Here is a test

Input XML:

<?xml version="1.0"?>
<loop name="Party Identification">
<segment name="Name and Address">
<element ref_des="NAD01">ABC</element>
<element ref_des="NAD03">Hello world</element>
</segment>
</loop>


XSLT:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<xsl:value-of select="//loop[@name='Party Identification']/segment[element[@ref_des='NAD01']='ABC']/element[@ref_des='NAD03']"/>
</xsl:template>

</xsl:stylesheet>

result:

Hello world


Hope this helps
Ivan Pedruzzi
Stylus Studio Team




Posttop
Sean SymesSubject: Xpath predicate numeric vs string help...
Author: Sean Symes
Date: 12 Jul 2005 10:21 PM
Thanks Ivan for your help.
I worked out the problem, basically the value for "<element ref_des="NAD01">" was on the next line with spaces preceeding it to "tab" it in, with the corresponding end tag on the line below that. When doing a string search the xpath parser was including the preceeding spaces as part of the search criteria. Take out the "formatting" and the statement worked, this also explains why numerics were working.

Cheers, Sean.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.