直接在节点集中指定元素 [英] Specify an element in a nodeset directly
问题描述
您好,
有没有办法直接访问节点集中的元素?
例如,如果使用:
< blahs rec_count =" 16">
< blah>
< yada> abc< / yada> ;
< / blah>
< blah>
< yada> 123< / yada>
< / blah>
< blah>
< yada> xyz< / yada>
< / blah>
< / blahs>
例如,我可以指定类似blahs / blah [2] / yada的内容并获得
价值123?
-Eric
Hello,
Is there any way to directly access an element in a nodeset?
For example, if working with:
<blahs rec_count="16">
<blah>
<yada>abc</yada>
</blah>
<blah>
<yada>123</yada>
</blah>
<blah>
<yada>xyz</yada>
</blah>
</blahs>
For instance, I could specify something like blahs/blah[2]/yada and get
the value of "123"?
-Eric
推荐答案
呃********** @ gmail.com 写道:
您好,
有没有办法直接访问节点集中的元素?
例如,如果使用:
< blahs rec_count =&q uot; 16">
< blah>
< yada> abc< / yada>
< / blah>
< blah>
< yada> 123< / yada>
< / blah>
< blah>
< yada> xyz< / yada>
< / blah>
< / blahs>
例如,我可以指定像blahs / blah [2] / yada这样的东西,并获得
的值123?
Hello,
Is there any way to directly access an element in a nodeset?
For example, if working with:
<blahs rec_count="16">
<blah>
<yada>abc</yada>
</blah>
<blah>
<yada>123</yada>
</blah>
<blah>
<yada>xyz</yada>
</blah>
</blahs>
For instance, I could specify something like blahs/blah[2]/yada and get
the value of "123"?
是的,正是如此。例如,在XSLT中,你会写出
< xsl:value-of select =" blahs / blah [2] / yada" />
但这与节点集没有任何关系。
它只是一个引用元素的XPath语句。
/// Peter
-
XML常见问题解答: http://xml.silmaril.ie/
Peter Flynn写道:
Peter Flynn wrote:
er**********@gmail.com 写道:
您好,
有没有办法直接访问节点集中的元素?
例如,如果使用:
< blahs rec_count =" 16">
< blah>
< yada> abc< / yada>
< / blah>
< blah>
<矢田&克t; 123< / yada>
< / blah>
< blah>
< yada> xyz< / yada>
< / blah>
< / blahs>
例如,我可以指定像blahs / blah这样的东西[2 ] / yada并获得
的值123?
Hello,
Is there any way to directly access an element in a nodeset?
For example, if working with:
<blahs rec_count="16">
<blah>
<yada>abc</yada>
</blah>
<blah>
<yada>123</yada>
</blah>
<blah>
<yada>xyz</yada>
</blah>
</blahs>
For instance, I could specify something like blahs/blah[2]/yada and get
the value of "123"?
是的,正是如此。例如,在XSLT中,你会写出
< xsl:value-of select =" blahs / blah [2] / yada" />
但是这与节点集没有任何关系。
它只是一个引用元素的XPath语句。
Yes, exactly that. In XSLT, for example, you would write
<xsl:value-of select="blahs/blah[2]/yada"/>
But this doesn''t have anything to do with nodesets.
It''s just an XPath statement referencing an element.
彼得,
嗯,更详细一点的情况是我传递了这个节点集的价值,我相信在参数中,这是正确的词。
所以我的整个XML文档看起来更像:
< mydoc>
< mystuff>
< blahs rec_count =" 3">
< blah>
< yada> abc< / yada>
< / blah>
< blah>
< yada> 123< / yada> ;
< / blah>
< blah>
< yada> xyz< / yada>
< / blah>
< / blahs>
< / mystuff>
< / mydoc>
我将blahs作为参数传递给模板,如下所示:
< xsl:apply-templates select =" somestuff">
< xsl:with-param name =" myblahs"
select =" / mydoc / mystuff / blahs">< / xsl:with-param>
< / xsl:apply-templates>
然后在我的模板中它看起来像:
< xsl:template match =" somestuff" >
< xsl:param name =" myblahs" />
....做一些事......
< / xsl:template>
所以在XML Spy中调试somestuff模板的转换,
如果我在XPath-Watch中查看
Peter,
Hmmm, well the situation in a little more detail is that I''m passing in
this nodeset, I believe that''s the right word, in a parameter.
So my entire XML document looks more like:
<mydoc>
<mystuff>
<blahs rec_count="3">
<blah>
<yada>abc</yada>
</blah>
<blah>
<yada>123</yada>
</blah>
<blah>
<yada>xyz</yada>
</blah>
</blahs>
</mystuff>
</mydoc>
I''m passing the blahs to a template as a parameter like so:
<xsl:apply-templates select="somestuff">
<xsl:with-param name="myblahs"
select="/mydoc/mystuff/blahs"></xsl:with-param>
</xsl:apply-templates>
Then in my template it looks something like:
<xsl:template match="somestuff">
<xsl:param name="myblahs"/>
.... Do some stuff...
</xsl:template >
So debugging the transformation of the somestuff template in XML Spy,
if I look at
myblahs,我会看到NodeSet [1]。如果我在
myblahs in the XPath-Watch, I see NodeSet[1]. If I click
on the NodeSet[1] beside the
旁边的NodeSet [1]上点击
这篇关于直接在节点集中指定元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!