使用XPath访问XML节点 邮区 雇员姓名
如何使用XPath基于上述XML的属性“name”选择节点使用XPath访问XML节点 邮区 雇员姓名,xml,xpath,Xml,Xpath,如何使用XPath基于上述XML的属性“name”选择节点?假设您想要选择值元素,该元素是属性的子元素,其名称为“Employee name” 其XPath表达式如下所示: <attributes> <attribute name="Mail Zone" property="alerts.p45" type=""> <value>mailzone</value> </attribute> <attribute
?假设您想要选择值元素,该元素是属性的子元素,其名称为“Employee name”
其XPath表达式如下所示:
<attributes>
<attribute name="Mail Zone" property="alerts.p45" type="">
<value>mailzone</value>
</attribute>
<attribute name="Employee Name" property="acm_alert_custom_attributes.cs11" type="">
<value>employeename</value>
</attribute>
<attribute name="Manager Name" property="alerts.p23" type="">
<value><managername></value>
</attribute>
<xsl:value-of select="/attributes/attribute[@name='Employee Name']/value"/>
在XSL中,您可以这样使用它:
/attributes/attribute[@name="Employee Name"]/value
以此为基础,您希望通过其他属性过滤结果。在这种情况下,您希望通过属性
元素的名称
属性进行过滤(您选择的名称可能会使事情难以理解)。过滤是使用您要过滤的元素上的[]
子句完成的。在您的例子中,这是属性
元素:
/attributes/attribute/value
现在你需要在过滤器里放些东西。@
符号表示要筛选的元素的属性,后跟所需属性的名称。然后将该属性与某个已知值进行比较,得出上述表达式:
/attributes/attribute[]/value
假设您想要选择值
元素,该元素是名为“Employee name”的属性
的子元素
其XPath表达式如下所示:
<attributes>
<attribute name="Mail Zone" property="alerts.p45" type="">
<value>mailzone</value>
</attribute>
<attribute name="Employee Name" property="acm_alert_custom_attributes.cs11" type="">
<value>employeename</value>
</attribute>
<attribute name="Manager Name" property="alerts.p23" type="">
<value><managername></value>
</attribute>
<xsl:value-of select="/attributes/attribute[@name='Employee Name']/value"/>
在XSL中,您可以这样使用它:
/attributes/attribute[@name="Employee Name"]/value
以此为基础,您希望通过其他属性过滤结果。在这种情况下,您希望通过属性
元素的名称
属性进行过滤(您选择的名称可能会使事情难以理解)。过滤是使用您要过滤的元素上的[]
子句完成的。在您的例子中,这是属性
元素:
/attributes/attribute/value
现在你需要在过滤器里放些东西。@
符号表示要筛选的元素的属性,后跟所需属性的名称。然后将该属性与某个已知值进行比较,得出上述表达式:
/attributes/attribute[]/value
我无法忍受XSL如此冗长,但XPath非常漂亮:)+1非常感谢您在我急需它时提供的帮助……再次感谢:)::)::):):@kishore:没问题。我希望你什么时候需要帮助就来。我强烈建议您花点时间学习更多关于XPath的知识,因为它是一个功能强大的工具,没有太复杂的语法。是的,我会学习的…我今天才开始使用它。。。。谢谢你的帮助和建议:):@Welbog:+1正确答案。但我会考虑编辑问题的标题和标签:严格地说,这是一个XPath问题。我无法忍受XSL是冗长的怪物,但XPath只是漂亮:“+1谢谢你在我急需它时的帮助很多……再次感谢:):(:):(:)::KySoR:没问题。我希望你什么时候需要帮助就来。我强烈建议您花点时间学习更多关于XPath的知识,因为它是一个功能强大的工具,没有太复杂的语法。是的,我会学习的…我今天才开始使用它。。。。谢谢你的帮助和建议:):@Welbog:+1正确答案。但是我会考虑编辑问题的标题和标签:严格来说,这是一个XPath问题。