How to get element with the highest ID using XSL

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>

Please Share us:
Please rate this snippet

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

Leave a Reply