Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2011, 12:14 PM
Registered User
 
Join Date: Feb 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to remove anchor tag from html using xslt

Hi All,
I've found one in the forums.But it's stripping all the other tags too.I have <div><p></p><h2></h2></h3></h3><a href="www.google.com>google</a></div>.I just want to strip off only the <a> tag keeping it's content google as is.Can anyone help me.

I really appreciate your time.

Thanks in advance.
 
Old February 25th, 2011, 12:22 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You've found one what?

Perhaps you could post what you have so far and we could see what you are doing wrong.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old February 25th, 2011, 12:37 PM
Registered User
 
Join Date: Feb 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I found one link :
http://help.hannonhill.com/discussio...ml-tag-in-xslt

<code>
<xsl:template name="removeTag">
<xsl:param name="html"/>
<xsl:param name="tag"/>
<xsl:choose>
<xsl:when test="contains($html, concat('&lt;',$tag))">
<xsl:value-of select="substring-before($html, concat('&lt;',$tag))"/>
<xsl:call-template name="removeTag">
<xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$html"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</code>
But it strips all the tags.Can anyone help me in removing only one <a> tag from html.

Thanks
 
Old February 25th, 2011, 01:31 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Please show us a sample input document and the corresponding output you want to create with XSLT. Do you have HTML elements or do you have escaped HTML markup? If you have HTML elements and you want to copy them, with the exception of 'a' elements then simply use
Code:
<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="a"/>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old February 28th, 2011, 06:33 AM
Registered User
 
Join Date: Feb 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default HI

Hi!!Thanks for the reply.
I've following xml.
<doc>
<title></title>
<author></author>
<description>
<p>This is description</p>
<div classs="a">
<h2>heading</h2>
<h3>h3 heading</h3>
<a href="www.gooogle.com">google</a>
</div>
</description>
</doc>
I want to strip only the <a href="www.gooogle.com"> keeping google and the other div and h2,h3 tags as is.
Can anyone tell me how to achieve this?I really appreciate your help.
 
Old February 28th, 2011, 06:39 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Martin almost got it right above. Change the 'a' template to this:

Code:
<xsl:template match="a"><xsl:apply-templates/></xsl:template>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old February 28th, 2011, 09:53 AM
Registered User
 
Join Date: Feb 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,thanks for your replyIt's working.But I am newbie to this xslt.So please help me.
<doc>
<title></title>
<author></author>
<desc1><a href="www.gooogle.com">google</a>
</desc1>
<description>
<p>This is description</p>
<div classs="a">
<h2>heading</h2>
<h3>h3 heading</h3>
<a href="www.gooogle.com">google</a>
</div>
</description>
</doc>
I have to remove <a >only from <description> not from <desc1>.Please help me.
Thanks in advance.
 
Old February 28th, 2011, 09:56 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Instead of
Code:
<xsl:template match="a"><xsl:apply-templates/></xsl:template>
use
Code:
<xsl:template match="description//a"><xsl:apply-templates/></xsl:template>
Please mark up your code samples with http://p2p.wrox.com/misc.php?do=bbcode#code in further posts.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old February 28th, 2011, 09:59 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Then change <xsl:template match="a"> to <xsl:template match="description/a">.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt to remove tag bricesteven XSLT 5 May 6th, 2010 09:29 AM
Remove Namespace from root tag using xslt namespce prefix nisargmca XSLT 0 February 24th, 2010 01:08 AM
An XML value in an Html tag (xslt) ismailc XSLT 9 October 19th, 2009 07:27 AM
Anchor Tag kapilmirchi ASP.NET 1.0 and 1.1 Basics 2 November 18th, 2008 05:57 AM
Want to pass value at href in anchor tag on xslt Abhinavnaresh XSLT 4 February 21st, 2008 04:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.