132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/rexml/parsers/xpathparser.rb', line 132
def expand(path_or_parsed)
if path_or_parsed.kind_of?(String)
parsed = parse(path_or_parsed)
else
parsed = path_or_parsed
end
path = ""
document = false
while parsed.size > 0
op = parsed.shift
case op
when :node
path << "node()"
when :attribute, :child, :following, :following_sibling,
:ancestor, :ancestor_or_self, :descendant, :descendant_or_self,
:namespace, :preceding, :preceding_sibling, :self, :parent
path << "/" unless path.size == 0
path << op.to_s.tr("_", "-")
path << "::"
when :any
path << "*"
when :qname
prefix = parsed.shift
name = parsed.shift
path << prefix+":" if prefix.size > 0
path << name
when :predicate
path << '['
path << predicate_to_path( parsed.shift ) { |x| expand(x) }
path << ']'
when :document
document = true
else
path << "UNKNOWN("
path << op.inspect
path << ")"
end
end
path = "/"+path if document
path
end
|