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?
 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.