Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XSLT - removing a tag from within text

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 6/17/2009 2:34:00 PM
gwoodhouse@g... 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent