Using the following XML

```
<?xml version="1.0" encoding="utf-8"?>
<Subjects>
  <Subject>
    <Title>Mr</Title>
    <Firstname></Firstname>
    <Surname></Surname>
    <Email></Email>
    <Incidents>
      <Incident>
        <ReferenceNo>meuen</ReferenceNo>
      </Incident>
    </Incidents>
    <TelephoneNos />
    <Employers />
    <BankAccounts />
  </Subject>
  <Subject>
    <Title>Mr</Title>
    <Firstname>Test</Firstname>
    <Surname>Test</Surname>
    <Email>test@test.com</Email>
    <Incidents>
      <Incident>
        <ReferenceNo>jkcsdlkjsdl</ReferenceNo>
      </Incident>
    </Incidents>
    <TelephoneNos />
    <Employers />
    <BankAccounts />
  </Subject>
</Subjects>

```

I want to extract all the ```ReferenceNo` tags and represent like this:

```
<RefNos>
   <RefNo>meuen</RefNo>
   <RefNo>jkcsdlkjsdl</RefNo>
</RefNos>

```

I have tried using the below XSLT:

```
<RefNos>
                <xsl:for-each select="(//*[local-name() ='ReferenceNo'][text()])">
                    <xsl:variable name="incidentNumbers" select="(//*[local-name() ='ReferenceNo'])"/>
                    <RefNo>
                        <xsl:value-of select="$incidentNumbers[text()]"/>
                    </RefNo>
                </xsl:for-each>
            </RefNos>

```

But this only gets the first populated item in the XML, if the top tag is empty it will only have the value of the bottom tag, and vice versa.