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 813395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:21:07+00:00 2026-05-15T01:21:07+00:00

I have looked up solutions on stackflow, but none of them seem to work

  • 0

I have looked up solutions on stackflow, but none of them seem to work for me. Here is my question. Lets say I have the following text :

Source:

<greatgrandparent>
<grandparent>
    <parent>
         <sibling>
              Hey, im the sibling .
          </sibling>
        <description>
        $300$ <br/> $250 <br/> $200! <br/> <p> Yes, that is right! <br/> You can own a ps3 for only $200 </p>
        </description>
    </parent>
    <parent>
         ... (SAME FORMAT)
    </parent>
       ... (Several more parents)
</grandparent>
</greatgrandparent>

Output:

 <newprice>
        $300$ <br/> $250 <br/> $200! <br/> Yes, that is right! <br/> You can own a ps3 for only $200  
    </newprice>

I can’t seem to find a way to do that.

Current XSL:

    <xsl:template match="/">
            <xsl:apply-templates />
        </xsl:template>

        <xsl:template match="greatgrandparents">
            <xsl:apply-templates />
        </xsl:template>

    <xsl:template match = "grandparent">

    <xsl:for-each select = "parent" >
          <newprice>
             <xsl:apply-templates>
           </newprice>
    </xsl:for-each>
    </xsl:template> 

<xsl:template match="description"> 
    <xsl:element name="newprice"> 
       <xsl:apply-templates/> 
    </xsl:element> 
</xsl:template> 

<xsl:template match="p"> 
   <xsl:apply-templates/> 
</xsl:template> 
  • 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-05-15T01:21:08+00:00Added an answer on May 15, 2026 at 1:21 am

    Use templates to define behavior on specific elements

    <!-- after standard identity template -->
    
    <xsl:template match="description">
        <xsl:element name="newprice">
           <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="p">
       <xsl:apply-templates/>
    </xsl:template>
    

    The first template says to swap description with newprice. The second one says to ignore the p element.

    If you’re unfamiliar with the identity template, take a look here for a few examples.

    EDIT: Given the new example, we can see that you want to only extract the description element and its contents. Notice that the template action starts with the match="/" template. We can use this control where our stylesheet starts and thus skip much of the riffraff we want to filter out.

    change the <xsl:template match="/"> to something more like:

        <xsl:template match="/">
            <xsl:apply-templates select="//description"/>   
            <!-- use a more specific XPath if you can -->
        </xsl:template>
    

    So altogether our solution looks like this:

    <xsl:stylesheet 
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
        exclude-result-prefixes="xs">
    
    <xsl:template match="/">
        <xsl:apply-templates select="//description" />
    </xsl:template>
    
    <!-- this is the identity template -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="description">
        <xsl:element name="newprice">
           <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="p">
       <xsl:apply-templates/>
    </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked through the solutions on stackoverflow and none of them seem to
I have looked at other solutions for this but can't find a similar issue:
I have looked at several possible solutions to my issue but did not find
I have looked at other solutions to this on this site, but can't see
I have a common problem, and have looked at several solutions but haven't seen
OK so I have looked theough the other solutions an no help. So here
I have looked into this time and again and have read solutions but they
I have looked for solutions to this on google for what seems like an
I have looked all around and only found solutions for python 2.6 and earlier,
I have looked for a solution , but nothing that fits my needs was

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.