質問編集履歴

3

解決した XPath 式を追記

2016/04/02 12:36

投稿

think49
think49

スコア18162

test CHANGED
File without changes
test CHANGED
@@ -64,11 +64,17 @@
64
64
 
65
65
  l = xpathResult.snapshotLength,
66
66
 
67
- textNodes = [];
67
+ textNodes = [],
68
+
69
+ textNode;
68
70
 
69
71
 
70
72
 
71
73
  while (i < l) {
74
+
75
+ textNode = xpathResult.snapshotItem(i++);
76
+
77
+
72
78
 
73
79
  if (textNode.data === data) {
74
80
 
@@ -140,6 +146,24 @@
140
146
 
141
147
 
142
148
 
149
+ ###回答
150
+
151
+
152
+
153
+ @ryls-nmm さんの回答により下記 XPath 式で解決できる事がわかりました(1つめの XPath 式は短縮形)。
154
+
155
+
156
+
157
+ ```
158
+
159
+ descendant::text()[.="JavaScript"]
160
+
161
+ descendant::text()[self::node()="JavaScript"]
162
+
163
+ ```
164
+
165
+
166
+
143
167
  ### 参考リンク
144
168
 
145
169
 

2

質問内容の表現を修正

2016/04/02 12:36

投稿

think49
think49

スコア18162

test CHANGED
File without changes
test CHANGED
@@ -136,7 +136,7 @@
136
136
 
137
137
 
138
138
 
139
- XPath 式のみで目的のテキストノードを参照する方法はないでしょうか。
139
+ XPath 式のみで目的のテキストノードの `XpathResult` を参照する方法はないでしょうか。
140
140
 
141
141
 
142
142
 

1

XPath 式のコード修正

2016/04/01 11:19

投稿

think49
think49

スコア18162

test CHANGED
File without changes
test CHANGED
@@ -70,7 +70,11 @@
70
70
 
71
71
  while (i < l) {
72
72
 
73
+ if (textNode.data === data) {
74
+
73
- textNodes.push(xpathResult.snapshotItem(i++));
75
+ textNodes.push(textNode);
76
+
77
+ }
74
78
 
75
79
  }
76
80
 
@@ -132,7 +136,7 @@
132
136
 
133
137
 
134
138
 
135
- XPath 式のみでテキストノードのリスト生成する方法はないでしょうか。
139
+ XPath 式のみで目的のテキストノード参照する方法はないでしょうか。
136
140
 
137
141
 
138
142