2 users online. Create an account or sign in to join them.Users
Grab elements before and after the specified tag
This is an open discussion with 5 replies, filed under XSLT.
Search
A similar question has been asked a few days ago, see my response there. :-)
Ok, thanks.
But given the example above, *[perceding-sibling::hr] should grab the elements before the hr-tag, right? The result is opposite...
*[preceding-sibling::hr] should match all elements that come after the hr. Since the template is empty, it will simply display nothing for those.
All other elements (the one before the hr) remain untouched and will be displayed.
To demonstrate it in action I've created a testcase on xpathr.
Odd, since the word preceding indicates otherwise :) How I could then do opposite? With following-sibling?
Edit: Or is it just me not understanding something?
Depends on the context. In the case of
<xsl:template match="*[preceding-sibling::hr]" mode="html" priority="1" />
we are matching elements with the following conditions:
*means all elements with any name[preceding-sibling::hr]means among those the ones that have a preceding sibling namedhr.
Obviously those conditions can only be met by elements following a hr.
What you're probably thinking of is a select like
<xsl:for-each select="preceding-sibling::hr">...
And you're right, in this situation you would get all hr elements preceding the current context node (also in reverse order). But yeah, that's a totally different use case. :-)
Yep, following-sibling is the complementary axis to preceding-sibling.
Create an account or sign in to comment.
Hello,
how I could grab elements before and after some element I specify? I mean if I have textarea and it saves XHTML, how I can grab all elements (like p-tag, for example) before hr-tag?
An example:
Maybe call / apply template for elements matching all elements before
<hr/>tag and another template for all elements after the<hr/>tag.