To get element with the highest ID using XSL you can use the following snippet.

XML:

<rootnode>
    <node>
        <id>3</id>
    </node>
    <node>
        <id>2</id>
    </node>
    <node>
        <id>1</id>
    </node>
	<node>
        <id>5</id>
    </node>
    <node>
        <id>4</id>
    </node>
</rootnode>

XSL:

<xsl:variable name="MaxNodeId"><xsl:value-of select="/rootnode/node[not(/rootnode/node/id > id)]/id"/></xsl:variable>

3 thought on “How to get element with the highest ID using XSL”

Leave a Reply