Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A6057106A6 for ; Thu, 30 Jan 2014 03:58:23 +0000 (UTC) Received: (qmail 79324 invoked by uid 500); 30 Jan 2014 03:58:21 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 78655 invoked by uid 500); 30 Jan 2014 03:58:13 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 78331 invoked by uid 99); 30 Jan 2014 03:58:10 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Jan 2014 03:58:10 +0000 Date: Thu, 30 Jan 2014 03:58:10 +0000 (UTC) From: "Michele Vivoda (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (JXPATH-163) String variables cannot be used as indices MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/JXPATH-163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13886230#comment-13886230 ] Michele Vivoda commented on JXPATH-163: --------------------------------------- Hi, >From XPath specification: http://www.w3.org/TR/xpath/#NT-PredicateExpr [8] Predicate ::= '[' PredicateExpr ']' [9] PredicateExpr ::= Expr A predicate filters a node-set with respect to an axis to produce a new node-set. For each node in the node-set to be filtered, the PredicateExpr is evaluated with that node as the context node, with the number of nodes in the node-set as the context size, and with the proximity position of the node in the node-set with respect to the axis as the context position; if PredicateExpr evaluates to true for that node, the node is included in the new node-set; otherwise, it is not included. A PredicateExpr is evaluated by evaluating the Expr and converting the result to a boolean. If the result is a number, the result will be converted to true if the number is equal to the context position and will be converted to false otherwise; if the result is not a number, then the result will be converted as if by a call to the boolean function. Thus a location path para[3] is equivalent to para[position()=3]. -------------- I read that if the Expr is a string, it is converted to true if the string is not empty, meaning 'any node' and so the first node is selected, if it were a "node set" selection instead of a "single node" then all nodes would have been selected. JXPath seems to comply with the spec. You may probably consider to use number() to force conversion to a number that then is checked against the position. /se:someArray[number($var)] > String variables cannot be used as indices > ------------------------------------------ > > Key: JXPATH-163 > URL: https://issues.apache.org/jira/browse/JXPATH-163 > Project: Commons JXPath > Issue Type: Bug > Affects Versions: 1.3 > Reporter: Alexander Koledzhikov > Priority: Minor > Attachments: commons-jxpath.patch > > > If I have a string variable, I cannot use it as an index in an xpath query. > For example, if var = "5", this query will return the 1st element, not the fifth: > /se:someArray[$var] -- This message was sent by Atlassian JIRA (v6.1.5#6160)