说我有以下XML …
- <root>
- <base>
- <tent key="1" color="red"/>
- <tent key="2" color="yellow"/>
- <tent key="3" color="blue"/>
- </base>
- <bucket>
- <tent key="1"/>
- <tent key="3"/>
- </bucket>
- </root>
… XPath会返回什么,“桶”包含“红色”和“蓝色”?
如果您使用的是XSLT,我建议您设置一个密钥:
- <xsl:key name="tents" match="base/tent" use="@key" />
然后你可以得到< tent>在< base>内使用特定密钥
- key('tents',$id)
那你可以做
- key('tents',/root/bucket/tent/@key)/@color
或者,如果$bucket是特定的< bucket>元件,
- key('tents',$bucket/tent/@key)/@color