Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

remove html tag from xml elment

Posted on 2013-05-29
8
Medium Priority
?
462 Views
Last Modified: 2013-05-30
Hi,
How remove any tag from xml element in XSL.
0
Comment
Question by:ethar1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39205936
If this prefers to your previous question...

Do you mean that you want to strip out all the escaped html tags?
well, that is a bit tricky, it requires writing some sort of XML parser in XSLT1

consider this

<p class=">abc">foo<bar</p>

pretty tricky to figure out whet is a tag in that string

I recommend that you have a second pass (new XSLT that removes the tags from inside a <p> element (and lets hope the html inside is wellformed)

Can you use XSLT2?
0
 

Author Comment

by:ethar1
ID: 39205961
lets say can we remove string start from  &lt;br /&gt;&lt;a   till end of element?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39205974
if you can specify what you need to remove, this is feasable

eg.
<br />
<a href="some-uri">foo</a>
...

would you need the foo to remain in <a> ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:ethar1
ID: 39205988
I need to remove From "<a"   to the end

Original:
description:re ayasd cdn specifgdfy wsdft you nes to resdve, sdfeasdble<a href="some-uri">foo</a>asfda asfgag



will be
description:re ayasd cdn specifgdfy wsdft you nes to resdve, sdfeasdble
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 39206003
that is easy

so you need substring-before(., '&lt;a')

and from that you need the <br /> removed?
0
 

Author Comment

by:ethar1
ID: 39206027
thanks this is wot I need.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39206384
The br needs to be removed recursively since it can be more than one

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:atom="http://www.w3.org/2005/Atom"
    version="1.0">
    
    <xsl:template match="/rss">
        <html>
            <head/>
            <body>
                <xsl:apply-templates select="channel"/>
            </body>
        </html>
    </xsl:template>
    
    <xsl:template match="channel">
        <h1><a href="{link}"><xsl:value-of select="title"/></a></h1>
        <xsl:apply-templates select="item[position() &lt;= 5]"/>
    </xsl:template>
    
    <xsl:template match="item">
        <h3><a href="{link}"><xsl:value-of select="title"/></a></h3>
        <p><xsl:value-of select="pubDate"/></p>
        <p><xsl:apply-templates select="description"/></p>
        <xsl:if test="enclosure[contains(@type, 'image')]">
            <img src="{enclosure/url}"/>
        </xsl:if>
    </xsl:template>
    
    <xsl:template match="description">
        <xsl:variable name="pre-link-str">
            <xsl:choose>
                <xsl:when test="contains(., '&lt;a')">
                    <xsl:value-of select="substring-before(., '&lt;a')"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="."/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:call-template name="remove-br">
            <xsl:with-param name="str" select="$pre-link-str"/>
        </xsl:call-template>
        
    </xsl:template>
    
    <xsl:template name="remove-br">
        <xsl:param name="str"/>
        <xsl:choose>
            <xsl:when test="contains($str, '&lt;br')">
                <xsl:value-of select="substring-before($str, '&lt;br')"/>
                <xsl:variable name="remainder-str" select="substring-after($str, '&lt;br')"/>
                <xsl:choose>
                    <xsl:when test="starts-with(normalize-space($remainder-str), '/&gt;')">
                        <xsl:call-template name="remove-br">
                            <xsl:with-param name="str" select="substring-after($remainder-str, '/&gt;')"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:call-template name="remove-br">
                            <xsl:with-param name="str" select="substring-after(substring-after($remainder-str, '&lt;/'), '&gt;')"/>
                        </xsl:call-template>
                     </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$str"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:ethar1
ID: 39207115
Thanks,
another question , please response.
http://www.experts-exchange.com/Hardware/Components/Q_28142696.html
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little history Back in 1997 when I built my first custom computer using the revolutionary Gateway website I didn’t have much to choose from except for the CPU. The race between computer manufacturers was held back by processor manufacturers. They…
More and more people are using the enhanced small form-factor pluggable (SFP+) tranceivers, and speed is of utmost importance. Testing of speeds are critical to ensure that the devices will meet the speed requirements. There are some testing challen…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question