Strontium_99
Strontium_99

Reputation: 1803

XSL manually selecting child nodes

Stupid question here. Got total brain-lock today.

I want to manually select a specific child node from xml. EG.

    <somenode>
         <somechild>Something</somechild>
         <somechild>Something else</somechild>
         <somechild>Something new</somechild>
         <somechild>Something old</somechild>
         <somechild>Something borrowed</somechild>
         <somechild>Something green ha ha</somechild>
    </somenode>

I know I can use

    <xsl:for-each select= 

to select all of them. But how, for example, can I just select node 2 using xsl 1.0 please?

I know its a pretty basic question, and I should know the answer. Just having a bad day.

Upvotes: 1

Views: 190

Answers (2)

ptomli
ptomli

Reputation: 11818

http://www.w3.org/TR/xpath/#NT-PredicateExpr

/doc/chapter[5]/section[2] selects the second section of the fifth chapter of the doc

So, for your example

/somenode/somechild[2]

Upvotes: 2

Andy
Andy

Reputation: 9048

This should do what you want:

<xsl:value-of select="/somenode/somechild[2]"/>

Upvotes: 2

Related Questions