How do I match the first element of the document using XSLT?

advertisements

this is a follow up for How can I select the first element using XSLT? .

<xml>
    <news>
        <newsitem>
            <dateCreated>2009-09-09</dateCreated>
            <summary>Something great happened</sumamry>
        </newsitem>
        <newsitem>
            <dateCreated>2009-09-08</dateCreated>
            <summary>Something bad happened</sumamry>
        </newsitem>
    </news>
    <news>
        <newsitem>
            <dateCreated>2009-09-07</dateCreated>
            <summary>Something really bad happened</sumamry>
        </newsitem>
    </news>
</xml>

How can I match against the first newsitem element in the document? the xsl:template match="//newsItem[1]" match sujested in the other question will get the first child. xsl:template match="(//newsItem)[1]" is not valid. The only other hints I've gotten involves doing some complicated/messy stuff with keys, it seems like there should be a better answer,


If I understand the question, I think you should use :

<xsl:template match="//news[1]/newsitem[1]"> to select the first item of all.