OK so I have an xslt issue that I cannot seem to solve. This is my second attempt at asking the question please do not mark as duplicate.
My issue is that I would like to include some HTML after the fourth <p>
tag in my document. The issue is that there can be <p>
tags with the attribute class="exclude"
If the <p>
tag has that class, I would like to not render that paragraph. At the same time, I would still like to render my included html after the 4th paragraph, regardless of the number of <p class="excludes"
there are
EDIT:: Here is the xsl I had previously. This would slot my included html into the 4th paragraph.
<xsl:template match="content/p[position() = 4]">
content include<xsl:apply-templates /></p>
</xsl:template>
Here are some example inputs / outputs
First is the base example where there are no <p class="excludes">
My input is:
<body>
<p></p>
<p></p>
<p></p>
<p></p>
include new HTML here
<p></p>
...
</body>
In that example, the html renders nicely after the 4th paragraph after passing through my xslt.
However, I need to take into account <p class="exclude">
Here is a more complicated example with <p class="exclude" being used >
<body>
<p class="exclude"></p> (should not be rendering on page)
<p></p>
<p></p>
<p></p>
<p></p>
include new HTML here
<p></p>
...
</body>
Notice that in this example, the included HTML is appearing after the 5th* paragraph because the first paragraph should not be rendering on the page, but at the same time I want the rendered HTML to be included after the 4th rendered paragraph. Lets look at one more example that is more complicated.
<body>
<p class="exclude"></p> (this should not be rendering on page)
<p></p>
<p class="exclude"></p> (this should not be rendering on page)
<p class="exclude"></p> ...
<p></p>
<p class="exclude"></p> ...
<p></p>
<p class="exclude"></p> ...
<p class="exclude"></p> ...
<p class="exclude"></p> ...
<p></p>
new HTML include here
<p></p>
...
<body>
<p class="exclude"></p>
Now, in my final example you can see that multiple <p class="excludes"
have been added and yes i still want the new html content to render after the 4th rendered paragraph, or in this example the 11th total over all paragraph.
If anyone has any xslt that could help me achieve this that would be great. Please keep in mind I am using xslt 1.0 Thanks in advance