[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Problem retaining HTML tags during XSL transformat

Subject: RE: Problem retaining HTML tags during XSL transformation
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 10 Jan 2007 16:35:23 -0000
xsl transform html tags
It's not clear to me what you're trying to do, so it's hard to suggest how
you should be doing it. But by passing an element containing mixed content
to a template such as transformXMLString that treats it as a string, you are
implicitly extracting the string value of the element - that is, you are
flattening the tree structure into a string, which destroys all the elements
and means there are no tags in the serialized result.

If you want to process the content of the text nodes, you have to do it one
node at a time.

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

> -----Original Message-----
> From: Ambika.Das@xxxxxxxxxxxxxxxxxx
> [mailto:Ambika.Das@xxxxxxxxxxxxxxxxxx]
> Sent: 10 January 2007 16:16
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Problem retaining HTML tags during XSL transformation
>
> Hi All,
>
> I am facing some problem in retaining the HTML tags during
> XSL transformation.
> Given below are the details.
>
> Input XML:
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <elem id="11" date="10 Jan 2007" time="16:55"> Non Title
> <title>Title Here</title> <text> <PRE> (Start of pre tag) <p>
> Within P </p> After P tag (End of pre tag) </PRE></text> </elem>
>
> XSL Code:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:output method="html" indent="no"/>
>
>    <xsl:template match="*">
> 		<xsl:copy>
> 		<xsl:copy-of select="@*"/>
> 		<xsl:apply-templates/>
> 		</xsl:copy>
> 	</xsl:template>
>
>   	<xsl:template match="elem">
> 		<xsl:text>Elem Id, News Details&#10;</xsl:text>
> 		<xsl:value-of select="@id"/>
> 		<xsl:text>,"</xsl:text>
> 		<xsl:call-template name="transformXMLString">
> 		    <xsl:with-param name="StringToTransform"
> select="$doubleQtReplaced"/>
> 		</xsl:call-template>
> 		<xsl:text>"</xsl:text>
> 	</xsl:template>
>
> 	<xsl:variable name="doubleQtReplaced">
>         <xsl:call-template name="replaceDblQt">
>             <xsl:with-param name="StringToTransform" select="/"/>
>         </xsl:call-template>
>     </xsl:variable>
>
> 	<xsl:template match="error">
>
> <xsl:text>SYSERROR_TYPE,SYSERROR_CODE,SYSERROR_DESC&#10;X,730,
> "</xsl:text>
> 		    <xsl:value-of select="error_text"/>
> 		<xsl:text>"</xsl:text>
> 	</xsl:template>
>
> 	<xsl:template  name="transformXMLString">
> 	    <xsl:param name="StringToTransform" select="."/>
> 	    <xsl:choose>
>             <xsl:when test="contains($StringToTransform,'&#10;')">
>                 <xsl:value-of
> select="substring-before($StringToTransform,'&#10;')"
> /><br/><xsl:call-template name="transformXMLString">
>                         <xsl:with-param name="StringToTransform">
>                             <xsl:value-of
> select="substring-after($StringToTransform,'&#10;')" />
>                         </xsl:with-param>
>                     </xsl:call-template>
>             </xsl:when>
> 	        <xsl:otherwise>
> 	            <xsl:value-of select="$StringToTransform"/>
> 	        </xsl:otherwise>
> 	    </xsl:choose>
> 	</xsl:template>
>
> 	<xsl:template name="replaceDblQt">
> 	    <xsl:param name="StringToTransform" select ="."/>
> 	    <xsl:choose>
> 	        <xsl:when test="contains($StringToTransform,'&#x22;')">
>                 <xsl:value-of
> select="substring-before($StringToTransform,'&#x22;')"/>""<xsl
> :call-template name="replaceDblQt">
>                         <xsl:with-param name="StringToTransform">
>                             <xsl:value-of
> select="substring-after($StringToTransform,'&#x22;')"/>
>                         </xsl:with-param>
>                     </xsl:call-template>
>             </xsl:when>
>             <xsl:otherwise>
> 	            <xsl:value-of select="$StringToTransform"/>
> 	        </xsl:otherwise>
> 	    </xsl:choose>
> 	</xsl:template>
>
> </xsl:stylesheet>
>
> Current Output:
>
> Elem Id, News Details
>
> 11,"<br>Non Title<br>Title Here<br><br> (Start of pre tag)
> <br><br>Within P<br><br>After P tag<br>(End of pre tag) <br>"
>
> Desired output:
>
> Elem Id, News Details
>
> 11,"<br>Non Title<br><title>Title Here</title><br><br>
> <PRE>(Start of pre tag) <br><p>Within P</p><br>After P
> tag<br>(End of pre tag) </PRE> <br>"
>
> Any clues?
>
> Thanks and Regards,
>  
> A P Das

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.