XSL TEST TWO CONDITIONS

I have the following xml. I want to check if the FormField node which has the element named 'Key' and has value of 'response' has a value set for the element named 'Value'. If the value element is empty then return false else return true:

<Form>
    <FormField>
        <Value>Jumper</Value>
        <Key>item</Key>
        <Label>Item</Label>
        <Type>string</Type>
    </FormField>
    <FormField>
        <Value>unsuccessful</Value>
        <Key>response</Key>
        <Label>Response</Label>
        <Type>string</Type>
    </FormField>
    <FormField>
        <Value/>
        <Key>notes</Key>
        <Label>Notes</Label>
        <Type>string</Type>
    </FormField>
<Form>

So for example the following would return true

<FormField>
        <Value>unsuccessful</Value>
        <Key>response</Key>
        <Label>Response</Label>
        <Type>string</Type>
    </FormField>

Where as the following would return false

<FormField>
        <Value/>
        <Key>response</Key>
        <Label>Response</Label>
        <Type>string</Type>
    </FormField>

How can I achieve this, any help appreciated?


Solution 1:

If by "has a value" you mean "contains a text node", then try:

<xsl:value-of select="exists(/Form/FormField[Key='response']/Value/text())"/>

or:

<xsl:value-of select="boolean(/Form/FormField[Key='response']/Value/text())"/>