Question

I have a xml like this and i want to get distinct values of using xpath. I tried using distinct-values, but it doesn't work. Can you help me? Thank you.

<schema>
    <animal href="http://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/Emperor_penguin.jpg/410px-Emperor_penguin.jpg">
        <id>1</id>
        <type>Bird</type>
    </animal>
    <animal href="https://upload.wikimedia.org/wikipedia/commons/thumb/5/56/White_shark.jpg/800px-White_shark.jpg">
        <id>2</id>
        <type>Fish</type>
    </animal>
    <animal href="http://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Pig-Nosed_Turtle_Carettochelys_insculpta_Underside_2000px.jpg/595px-Pig-Nosed_Turtle_Carettochelys_insculpta_Underside_2000px.jpg">
        <id>3</id>
        <type>Reptile</type>
    </animal>
    <animal href="http://upload.wikimedia.org/wikipedia/commons/thumb/4/45/Mobula_breaching.jpg/800px-Mobula_breaching.jpg">
        <id>4</id>
        <type>Fish</type>
    </animal>
</schema>
Was it helpful?

Solution

Assuming you are looking for distinct type elements use /schema/animal/type[not(. = ../preceding-sibling::animal/type)].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top