1 Package com.interrupt.cc.xpath;
\r
4 // declare namespace xq='http://xmlbeans.apache.org/samples/xquery/employees';
\r
6 // $this/xq:employees/xq:employee/xq:phone[contains(., '(206)')]
\r
8 /* ./child::node()[1]/attribute::name
\r
10 *) Find value of the name attribute of the first element in the XML document
\r
12 1) The first section is only a dot (.). A dot at the start of a query means you want to start your search from the beginning of the XML document.
\r
14 2) The second section (child::node()[1]) says: Find the first child element node. The combined effect of the first and second portions (./child::node()[1]) is like saying: Find the first element of this XML document.
\r
16 3) The third section (attribute::name) says: Find the value of an attribute name. The combined effect of the query is like saying: .
\r
20 /* ./child::node()[1]/child::service/child::port/child::soap:address/attribute::location
\r
22 *) Find the first child node of the XML document, then find a service child element within the first child, then find a port element inside the service element, then look inside the port element for an address element that belongs to the SOAP namespace and return the value of its location attribute.
\r
44 alphanum_varname_seq
\r
70 Expr = ExprSingle ("," ExprSingle)*
\r
71 ExprSingle = ForExpr
\r
75 ForExpr = SimpleForClause "return" ExprSingle
\r
76 SimpleForClause = "for" "$" VarName "in" ExprSingle ("," "$" VarName "in" ExprSingle)*
\r
78 QuantifiedExpr = ("some" | "every") "$" VarName "in" ExprSingle ("," "$" VarName "in" ExprSingle)* "satisfies" ExprSingle
\r
80 IfExpr = "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle
\r
82 OrExpr = AndExpr ( "or" AndExpr )*
\r
84 AndExpr = ComparisonExpr ( "and" ComparisonExpr )*
\r
86 ComparisonExpr = RangeExpr ( (ValueComp
\r
88 | NodeComp) RangeExpr )?
\r
90 RangeExpr = AdditiveExpr ( "to" AdditiveExpr )?
\r
92 AdditiveExpr = MultiplicativeExpr ( ("+" | "-") MultiplicativeExpr )*
\r
94 MultiplicativeExpr = UnionExpr ( ("*" | "div" | "idiv" | "mod") UnionExpr )*
\r
96 UnionExpr = IntersectExceptExpr ( ("union" | "|") IntersectExceptExpr )*
\r
98 IntersectExceptExpr = InstanceofExpr ( ("intersect" | "except") InstanceofExpr )*
\r
100 InstanceofExpr = TreatExpr ( "instance" "of" SequenceType )?
\r
102 TreatExpr = CastableExpr ( "treat" "as" SequenceType )?
\r
104 CastableExpr = CastExpr ( "castable" "as" SingleType )?
\r
106 CastExpr = UnaryExpr ( "cast" "as" SingleType )?
\r
108 UnaryExpr = ("-" | "+")* ValueExpr
\r
110 ValueExpr = PathExpr
\r
112 GeneralComp = "=" | "!=" | "<" | "<=" | ">" | ">="
\r
114 ValueComp = "eq" | "ne" | "lt" | "le" | "gt" | "ge"
\r
116 NodeComp = "is" | "<<" | ">>"
\r
118 PathExpr = ("/" RelativePathExpr?)
\r
119 | ("//" RelativePathExpr)
\r
120 | RelativePathExpr /* xgs: leading-lone-slash */
\r
122 RelativePathExpr = StepExpr (("/" | "//") StepExpr)*
\r
124 StepExpr = FilterExpr | AxisStep
\r
141 descendant-or-self
\r
145 AxisStep = (ReverseStep | ForwardStep) PredicateList
\r
147 ForwardStep = (ForwardAxis NodeTest) | AbbrevForwardStep
\r
149 ForwardAxis = ("child" "::")
\r
150 | ("descendant" "::")
\r
151 | ("attribute" "::")
\r
153 | ("descendant-or-self" "::")
\r
154 | ("following-sibling" "::")
\r
155 | ("following" "::")
\r
156 | ("namespace" "::")
\r
158 AbbrevForwardStep = "@"? NodeTest
\r
160 ReverseStep = (ReverseAxis NodeTest) | AbbrevReverseStep
\r
162 ReverseAxis = ("parent" "::")
\r
163 | ("ancestor" "::")
\r
164 | ("preceding-sibling" "::")
\r
165 | ("preceding" "::")
\r
166 | ("ancestor-or-self" "::")
\r
168 AbbrevReverseStep = ".."
\r
170 NodeTest = KindTest | NameTest
\r
172 NameTest = QName | Wildcard
\r
176 | ("*" ":" NCName) /* ws: explicit */
\r
178 FilterExpr = PrimaryExpr PredicateList
\r
180 PredicateList = Predicate*
\r
182 Predicate = "[" Expr "]"
\r
184 PrimaryExpr = Literal | VarRef | ParenthesizedExpr | ContextItemExpr | FunctionCall
\r
186 Literal = NumericLiteral | StringLiteral
\r
188 NumericLiteral = IntegerLiteral | DecimalLiteral | DoubleLiteral
\r
190 VarRef = "$" VarName
\r
194 ParenthesizedExpr = "(" Expr? ")"
\r
196 ContextItemExpr = "."
\r
199 * Node Set Functions
\r
201 Function: number last()
\r
202 Function: number position()
\r
203 Function: number count(node-set)
\r
204 Function: node-set id(object)
\r
205 Function: string local-name(node-set?)
\r
206 Function: string namespace-uri(node-set?)
\r
207 Function: string name(node-set?)
\r
213 Function: string string(object?)
\r
214 Function: string concat(string, string, string*)
\r
215 Function: boolean starts-with(string, string)
\r
216 Function: boolean contains(string, string)
\r
217 Function: string substring-before(string, string)
\r
218 Function: string substring-after(string, string)
\r
219 Function: string substring(string, number, number?)
\r
220 Function: number string-length(string?)
\r
221 Function: string normalize-space(string?)
\r
222 Function: string translate(string, string, string)
\r
226 * Boolean Functions
\r
228 Function: boolean boolean(object)
\r
229 Function: boolean not(boolean)
\r
230 Function: boolean true()
\r
231 Function: boolean false()
\r
232 Function: boolean lang(string)
\r
238 Function: number number(object?)
\r
239 Function: number sum(node-set)
\r
240 Function: number floor(number)
\r
241 Function: number ceiling(number)
\r
242 Function: number round(number)
\r
245 FunctionCall = QName "(" (ExprSingle ("," ExprSingle)*)? ")" /* xgs: reserved-function-names */
\r
248 SingleType = AtomicType "?"?
\r
250 SequenceType = ("empty-sequence" "(" ")")
\r
251 | (ItemType OccurrenceIndicator?)
\r
253 OccurrenceIndicator = "?" | "*" | "+" /* xgs: occurrence-indicators */
\r
255 ItemType = KindTest | ("item" "(" ")") | AtomicType
\r
259 KindTest = DocumentTest
\r
262 | SchemaElementTest
\r
263 | SchemaAttributeTest
\r
269 AnyKindTest = "node" "(" ")"
\r
271 DocumentTest = "document-node" "(" (ElementTest | SchemaElementTest)? ")"
\r
273 TextTest = "text" "(" ")"
\r
275 CommentTest = "comment" "(" ")"
\r
277 PITest = "processing-instruction" "(" (NCName | StringLiteral)? ")"
\r
279 AttributeTest = "attribute" "(" (AttribNameOrWildcard ("," TypeName)?)? ")"
\r
281 AttribNameOrWildcard = AttributeName | "*"
\r
283 SchemaAttributeTest = "schema-attribute" "(" AttributeDeclaration ")"
\r
285 AttributeDeclaration = AttributeName
\r
287 ElementTest = "element" "(" (ElementNameOrWildcard ("," TypeName "?"?)?)? ")"
\r
289 ElementNameOrWildcard = ElementName | "*"
\r
291 SchemaElementTest = "schema-element" "(" ElementDeclaration ")"
\r
293 ElementDeclaration = ElementName
\r
295 AttributeName = QName
\r
297 ElementName = QName
\r