Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining Conditions in XPath and XSLT

Tags:

xslt

xpath

I am trying to build an XPath select just the 'Phone' number from the following:

<element identifier="ContactPoint" version="Local">
    <qualifier name="Phone" type="refining"/>
    01234 567890
</element>
<element identifier="ContactPoint" version="Local">
    <qualifier name="Email" type="refining"/>
    [email protected]
</element>

In my XSLT, I have the following:

<TelNumber>
    <xsl:value-of select="./element[@identifier='ContactPoint']"/>
</TelNumber>

But obviously this will just select the first instance. How would I combine conditions into one select to ensure I am only selecting the value of "element" with a "Phone" qualifier child?

Thanks!

like image 658
Ryall Avatar asked Aug 19 '09 10:08

Ryall


People also ask

How do I combine two attributes in XPath?

The syntax for locating elements through XPath- Multiple Attribute can be written as: //<HTML tag>[@attribute_name1='attribute_value1'][@attribute_name2='attribute_value2]

Can we use and condition in XPath?

Using OR & AND In the following XPath expression, it identifies the elements whose single or both conditions are true. Highlight both elements as the 'First Name' element having attribute 'id' and the 'Last Name' element having attribute 'name'. In the AND expression, two conditions are used.

How do you handle multiple elements with the same XPath?

If an xpath refers multiple elements on the DOM, It should be surrounded by brackets first () and then use numbering. if the xpath refers 4 elements in DOM and you need 3rd element then working xpath is (common xpath)[3].

What does double colon mean in XPath?

The forward axis returns nodes in document order, the reverse axis returns nodes in reverse document order. A double colon :: is used to separate the axis specifier from the node test. Forward Axis. child. descendant.


1 Answers

.\element[@identifier='ContactPoint' and qualifier/@name='Phone']

like image 71
AakashM Avatar answered Nov 03 '22 11:11

AakashM