Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8079147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:01:01+00:00 2026-06-05T16:01:01+00:00

I am having an xslt issue that I cannot seem to solve. Right now

  • 0

I am having an xslt issue that I cannot seem to solve. Right now I have this template match: <xsl:template match="bodytext/p[position() = 4]">

And this works fine. When the 4th paragraph renders I include some content. The issue is that sometimes the <p> element can have a class class="exclude"

I am trying to find a good way to exclude the <p> tags that have that class attribute. The problem is that there can be as many <p class="exclude"> as wanted/needed before or at the 4th paragraph while still rendering the 1st, 2nd, and 3rd paragraphs that do not have “exclude” class. So if a document looks like:

<p></p>
<p class="exclude"></p>
<p class="exclude"></p>
<p class="exclude"></p>
<p></p>
<p class="exclude"></p>
<p></p>
<p></p>

I only want to match the template:

<p></p>
<p></p>
<p></p>
<p></p>

Another example would be an input of:

<p></p>
<p></p>
<p></p>
<p class="exclude"></p>
<p class="exclude"></p>
<p class="exclude"></p>
<p class="exclude"></p>
<p class="exclude"></p>
<p class="exclude"></p>
<p></p>

and output of:

<p></p>
<p></p>
<p></p>
<p></p>

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:01:02+00:00Added an answer on June 5, 2026 at 4:01 pm

    You can do it like this:

    <xsl:apply-templates 
        select="bodytext/p[not(@class = 'exclude')][position() = 4]"/>
    

    Here’s the test case. Applying the following transformation:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
        <xsl:strip-space elements="*"/>
    
        <xsl:template match="node() | @*">
            <xsl:copy>
                <xsl:apply-templates select="node() | @*"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="/">
            <xsl:apply-templates 
                select="bodytext/p[not(@class = 'exclude')][position() = 4]"/>
        </xsl:template>
    
    </xsl:stylesheet>
    

    To:

    <bodytext>
        <p></p>
        <p class="exclude"></p>
        <p class="exclude"></p>
        <p class="exclude"></p>
        <p></p>
        <p class="exclude"></p>
        <p></p>
        <p>test</p>
    </bodytext>
    

    Produces:

    <p>test</p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm frustratingly new to xslt and have a question that I just can't seem
having read the docs, https://docs.djangoproject.com/en/dev/topics/signals/ i have created this in my signals.py file: from
I'm new to XML/XSLT and am having an issue trying to change an image
I have an xslt script that transforms an xml file to another xml file.
I have an xslt stylesheet that needs to call a C# XSLT extension function
I'm having problems understanding xslt. In my source document I have to find the
I'm having some trouble with xslt and was hoping that maybe someone here can
I'm having a problem with including xslt templates. I have a.xslt which includes b.xslt
I am working on a project right now that involves receiving a message from
Having some strange behavior here. I have some XSLT which generates some html with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.