ethar turky
asked on
remove html tag from xml elment
Hi,
How remove any tag from xml element in XSL.
How remove any tag from xml element in XSL.
ASKER
lets say can we remove string start from <br /><a till end of element?
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> ?
eg.
<br />
<a href="some-uri">foo</a>
...
would you need the foo to remain in <a> ?
ASKER
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>asf da asfgag
will be
description:re ayasd cdn specifgdfy wsdft you nes to resdve, sdfeasdble
Original:
description:re ayasd cdn specifgdfy wsdft you nes to resdve, sdfeasdble<a href="some-uri">foo</a>asf
will be
description:re ayasd cdn specifgdfy wsdft you nes to resdve, sdfeasdble
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks this is wot I need.
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() <= 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(., '<a')">
<xsl:value-of select="substring-before(., '<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, '<br')">
<xsl:value-of select="substring-before($str, '<br')"/>
<xsl:variable name="remainder-str" select="substring-after($str, '<br')"/>
<xsl:choose>
<xsl:when test="starts-with(normalize-space($remainder-str), '/>')">
<xsl:call-template name="remove-br">
<xsl:with-param name="str" select="substring-after($remainder-str, '/>')"/>
</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, '</'), '>')"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$str"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
ASKER
Thanks,
another question , please response.
https://www.experts-exchange.com/questions/28142696/random-xsl-select.html
another question , please response.
https://www.experts-exchange.com/questions/28142696/random-xsl-select.html
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<
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?