XSLT execute apply templates only once

690 Views Asked by At

XSLT-

<Address>
<xsl:apply-templates select="Orders/Rows/Row[addres_no/number = $addr_no]" />
</Address>

Input XML-

<Orders>
    <Rows>
        <Row>
            <addres_no>
                <number>1</number>
            </addres_no>
        </Row>
        <Row>
            <addres_no>
                <number>1</number>
            </addres_no>
        </Row>
        <Row>
            <addres_no>
                <number>3</number>
            </addres_no>
        </Row>
    </Rows>
</Orders>

In the example above, I am executing a template if the address number matches the addr_no variable value.

I want the "apply-templates" to execute only once, even if multiple matches are found.

For example if $addr_no = 1, it would find two matches, but I only want to get the first available one.

I tried -

<xsl:apply-templates select="Orders/Rows/Row[addres_no/number = $addr_no][1]" />

but that did not work.

0

There are 0 best solutions below