Hello my name is Alex

My surname is Thomas

My middle name is Jame" />

Hello my name is Alex

My surname is Thomas

My middle name is Jame" />

Hello my name is Alex

My surname is Thomas

My middle name is Jame"/>

Select first child <p> in Deliverance

175 views Asked by At

Given the following content:

<div class="content">
  <div id="brian">
    <p>Hello my name is Alex</p>
    <p>My surname is Thomas</p>
    <p>My middle name is James</p>
    <p>true story...</p>
  </div>
</div>

And with the following in my theme:

<div id="dave" />

How so I replace #dave with the first paragraph? I've tried:

  • <replace content="//div[@class='content']/p" theme="div#dave" />
  • <replace content="//div[@class='content']/p[1]" theme="div#dave" />
  • <replace content="children://div[@class='content']/p" theme="meta#description" />

Neither worked... Please note that .content is buried fairly deep and can change position, so using its XPath is not an option. By xPath I mean /div/div/p[1] etc...

3

There are 3 answers

2
Vito On
<replace css:content=".content p:first-child" css:theme="#dave" />

Could be the solution ;) Vito

2
Giacomo Spettoli On

For a pure xslt solution try this:

<replace content="//div[@class='content']/p[1]" theme="div#dave" />

edit:

i meant:

 <replace content="//div[@class='content']//p[1]" css:theme="div#dave" />

or

<replace content="//div[@class='content']/div/p[1]" css:theme="div#dave" />
0
ejucovy On

The :first-child CSS selector should work -- so it would be something like

<replace content="p:first-child" theme="#dave" />