![]() |
XSLT - removing a tag from within text
Hi All,
This should be so easy but is so incredibly not easy that im about ready to kill myself. What i have is this xml: <node> <start_time>00:00:<span class="hit">11</span></start_time> </node> and i just want it to output: 00:00:00 Luckily for me XSLT is ridiculous, making this problem unsolvable. i've tried: fn:substring-before(start_time, "<") but of course, thats far too straight forward so it doesnt work. I've tried: <xsl:apply-templates select="start_time"/> <xsl:template match="span"> </xsl:template> but of course, that, although esoteric, doesn't work either I've tried string(start_time), i've even tried to do fn:escape-uri and tried to replace those values but that doesnt work either! Please someone for the love of all that is good in this world help me!!!!! |
Re: XSLT - removing a tag from within text
Sorry, the output should be 00:00:11 in that case.
|
Re: XSLT - removing a tag from within text
gwoodhouse@gmail.com wrote:
> What i have is this xml: > <node> > <start_time>00:00:<span class="hit">11</span></start_time> > </node> > > and i just want it to output: > 00:00:00 This is easy: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:apply-templates select="node/start_time"/> </xsl:template> </xsl:stylesheet> -- Martin Honnen http://msmvps.com/blogs/martin_honnen/ |
Re: XSLT - removing a tag from within text
Martin Honnen a écrit :
> gwoodhouse@gmail.com wrote: > >> What i have is this xml: >> <node> >> <start_time>00:00:<span class="hit">11</span></start_time> >> </node> >> >> and i just want it to output: >> 00:00:00 > > This is easy: > > <xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> > > <xsl:output method="text"/> > > <xsl:template match="/"> > <xsl:apply-templates select="node/start_time"/> > </xsl:template> > > </xsl:stylesheet> this one should work too: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> </xsl:stylesheet> -- Cordialement, /// (. .) --------ooO--(_)--Ooo-------- | Philippe Poulard | ----------------------------- http://reflex.gforge.inria.fr/ Have the RefleX ! |
Re: XSLT - removing a tag from within text
Ok, so, i can't include the whole code or else my company would beat
the hell out of me. Here is a more complete and realworld snippet: <transcript> <chapter> <chapter_hitcount><![CDATA[1 hit]]></chapter_hitcount> <start_time><![CDATA[01:11:04]]></start_time> <end_time><![CDATA[01:<span class="hit">22</span>:45]]></end_time> <abstract> You can see here how you would want <span class="hit">22</span> to be displayed</abstract> </chapter> </transcript> xslt: <xsl:template match='chapter'> <span class="timespan"> (<xsl:apply-templates select="start_time"/> - <xsl:apply-templates select="end_time"/>) </span> <div class="abstract"> <span class="abstractLead">Summary:</span> <xsl:apply-templates select="abstract"/> </div> </xsl:template> In this example i would want the output to display the "abstract" output with the span tag, i would want the "end_time" tag to display without the <span> tag. |
Re: XSLT - removing a tag from within text
Philippe Poulard wrote:
> Martin Honnen a écrit : >> gwoodhouse@gmail.com wrote: >> >>> What i have is this xml: >>> <node> >>> <start_time>00:00:<span class="hit">11</span></start_time> >>> </node> >>> >>> and i just want it to output: >>> 00:00:00 > this one should work too: > > <xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> > > <xsl:output method="text"/> > > </xsl:stylesheet> That would output additional white space. -- Martin Honnen http://msmvps.com/blogs/martin_honnen/ |
Re: XSLT - removing a tag from within text
gwoodhouse@gmail.com wrote:
> Ok, so, i can't include the whole code or else my company would beat > the hell out of me. Here is a more complete and realworld snippet: > > <transcript> > <chapter> > <chapter_hitcount><![CDATA[1 hit]]></chapter_hitcount> > <start_time><![CDATA[01:11:04]]></start_time> > <end_time><![CDATA[01:<span class="hit">22</span>:45]]></end_time> > <abstract> You can see here how you would want <span > class="hit">22</span> to be displayed</abstract> > </chapter> > </transcript> > > xslt: > <xsl:template match='chapter'> > <span class="timespan"> > (<xsl:apply-templates select="start_time"/> - <xsl:apply-templates > select="end_time"/>) > </span> > <div class="abstract"> > <span class="abstractLead">Summary:</span> <xsl:apply-templates > select="abstract"/> > </div> > </xsl:template> > > In this example i would want the output to display the "abstract" > output with the span tag, i would want the "end_time" tag to display > without the <span> tag. Well that is completely different from what you posted before and in the sample above the 'abstract' element contains a 'span' element while the 'end_time' element does not contain a 'span' element, instead it contains pure text with escaped markup. The 'abstract' element can easily be solved with XSLT <xsl:template match="abstract"> <div class="{local-name()}"> <xsl:apply-templates/> </div> </xsl:template> then you need to add a template matching span that copies that <xsl:template match="span"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> The 'end_time' element is difficult. If I had a choice I would solve it with XSLT 2.0 and David Carlisle's HTML parser done in XSLT (http://www.dcarlisle.demon.co.uk/htmlparse.xsl) but I don't know whether that is an option for you. -- Martin Honnen http://msmvps.com/blogs/martin_honnen/ |
Re: XSLT - removing a tag from within text
Yeah, problem is none of that works.
There are lots of places where many many values need to print out a <span> tag. What i want is a way of removing <span class="hit"> from the output of ONE tag. Please someone tell me there is a way of doing that, not by changing the way everything else works, just by removing the damn <span> tag from one output. Surely, SURELY, XSLT can manage to create a variable from "a bit of <span>text</span>" that contains "a bit of text". Surely?!?! |
Re: XSLT - removing a tag from within text
So, basically, i want this:
end_time contents: 00:00:<span class="hit">11</span> <xsl:variable name="safeend"> <xsl:call-template name="removeSpan"> <xsl:with-param name="variable" select="end_time"/> </xsl:call-template> </xsl:variable> <xsl:template name="removeSpan"> <xsl:param name="variable"/> <xsl:value-of select="fn:substring-before($variable, '<')"/> </xsl:template> with safeend being: 00:00:11 Yes it's in a CDATA tag but that doesn't seem to change anything at all. |
Re: XSLT - removing a tag from within text
gwoodhouse@gmail.com wrote:
> Yeah, problem is none of that works. None of what? > There are lots of places where many many values need to print out a > <span> tag. > > What i want is a way of removing <span class="hit"> from the output of > ONE tag. http://www.w3.org/TR/xpath-functions/#func-replace http://www.dpawson.co.uk/xsl/sect2/r....html#d9701e43 -- Martin Honnen http://msmvps.com/blogs/martin_honnen/ |
| All times are GMT. The time now is 03:49 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.