Change attribute for 4th <p> tag

Hi all,

I need to create an anchor for the fourth paragraph of a page. I wanted to use an id but have had no luck in trying to create a loop to target the fourth <p> tag and add the id (maybe I need to add the id then remove it?). I have tried something like the code below, but with no luck. Any help would be greatly appreciated! (The code below isn't breaking anything, it just doesn't seem to be doing the trick.)

<xsl:template match="p">
            <xsl:choose>
                <xsl:when test="id('entrytext')/child::self[position()=3]">
                    <p id="jump"><xsl:apply-templates/></p>
                </xsl:when>
                <xsl:otherwise>
                    <p><xsl:apply-templates/></p>
                </xsl:otherwise>
            </xsl:choose>
</xsl:template>
tepper714Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

darkyin87Commented:
Try something like this.

<xsl:template match="node[@id='jump']"/>
0
zc2Commented:
You probably need something like follows, but please provide more details to let us find more precised solution.
<xsl:template match="p">
	<xsl:copy>
		<xsl:if test="position()=4">
			<xsl:attribute name="id">jump</xsl:attribute>
  		</xsl:if>
		<xsl:apply-templates/>
	</xsl:copy>
</xsl:template>

Open in new window

0
zc2Commented:
You said an HTML anchor? Then you don't need mess with the ids, just create the anchor element:
<xsl:template match="p">
	<xsl:copy>
		<xsl:if test="position()=4">
			<a name="jump"/>
  		</xsl:if>
		<xsl:apply-templates/>
	</xsl:copy>
</xsl:template>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tepper714Author Commented:
zc2,this is working but it's counting the first <p> tag as the 3rd position. Would it be counting the both teh open and closed <p> tags?
0
tepper714Author Commented:
Ok, this is working using position 15 (no idea why, but it's working). Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.