Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Re: preserving html tags

From: "Michael Kay" <mike@------------>
To:
Date: 11/1/2006 5:57:00 PM
Normally the answer would be to copy the content using copy-of rather than
value-of to retain the tree structure. But trimming the text while retaining
the tree structure is a bit more of a challenge. It needs a recursive walk
of the subtree, passing the length of text processed so far as a parameter
to each template, and terminating when this length reaches your threshold.

Or you could approximate by doing this only one level deep, which is a fair
bit easier.

Concerning your title, you really need to understand that there are no tags
involved here. You are processing a tree of element and text nodes, and you
won't solve the problem unless you understand it in those terms.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Karl [mailto:call14@xxxxxxxxx] 
> Sent: 01 November 2006 16:51
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Re: preserving html tags
> 
> My problem is related to rendering html content like 
> "content<b>bold</b>...contents" as it in xml into the output 
> html. I am using <apply-templates> to select content but 
> later use <value-of> to trim it. Suspect <value-of> removing 
> the html tags (not sure), but are there any other way to get 
> proper results?
>  
> Basically my xml looks something like
> 
> 		<Introduction>
> 			<Title>Introduction</Title>
> 			<Paragraph>In this session we 
> <sub>this</sub><b>Bold</b> take a closer look at what is 
> meant by strategy. The classical approach to strategic 
> management  ... big para content
>  			</Paragraph>
>  			<Paragraph/>
> 		</Introduction>
> 		<Section/>
> 
> I am trying to output 1st para of certain elements & limit 
> the para content to certain char limit. so, in my xsl 
> 
> 		<xsl:for-each select="//Introduction | 
> //Session/Section/SubSection | //References | //Acknowledgements">
> 			<xsl:variable name="titleContent">	
> 			
> 				<xsl:value-of select="name()"/>
> 			</xsl:variable>
> 			<xsl:variable name="paraContent">
> 				<xsl:if test=".//Paragraph[1] 
> and (name() = 'SubSection' or
> name() = 'Introduction')">
> 					<xsl:apply-templates 
> select=".//Paragraph[1]"/>
> 				</xsl:if>
> 			</xsl:variable>
> 			<p class="paradefault">
> 				<xsl:call-template name="trimPara">
> 					<xsl:with-param 
> 
> name="stringLenRequired">200</xsl:with-param>
> 					<xsl:with-param 
> name="stringInput" 
> 
> select="$paraContent"/>
> 				</xsl:call-template>
> 			</p>
> 		</xsl:for-each>
> 
> and then ...
> 
> 	<xsl:template name="trimPara">
> 		<!-- pass the string to be cropped with 
> required string length -->
> 		<xsl:param name="stringLenRequired"/>
> 		<xsl:param name="stringInput"/>
> 		<xsl:value-of 
> 
> select="substring($stringInput,1,number($stringLenRequired))"/>
> 		<xsl:value-of 
> 
> select="substring-before(concat(substring($stringInput,number(
> $stringLenRequired)+1,number($
> 
> stringLenRequired) +20),' ' ),' ')"/> <!-- to make it a full word -->
> 		<xsl:if test="string-length($stringInput) > 
> 
> number($stringLenRequired)">...</xsl:if>
> 	</xsl:template>
> 
> 
> This results in an html output having no <b>, <sup> or any 
> other html tags - while the content within them gets thro. I 
> dont know where those html tags gets striped. Pls let me know 
> how can this be fixed.
> 
> Thanks in adv.
> karl
> 
> Send instant messages to your online friends 
> http://uk.messenger.yahoo.com


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