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(_dot_)Das(_at_)iflexsolutions(_dot_)com
[mailto:Ambika(_dot_)Das(_at_)iflexsolutions(_dot_)com]
Sent: 10 January 2007 16:16
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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 </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 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,' ')">
<xsl:value-of
select="substring-before($StringToTransform,' ')"
/><br/><xsl:call-template name="transformXMLString">
<xsl:with-param name="StringToTransform">
<xsl:value-of
select="substring-after($StringToTransform,' ')" />
</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,'"')">
<xsl:value-of
select="substring-before($StringToTransform,'"')"/>""<xsl
:call-template name="replaceDblQt">
<xsl:with-param name="StringToTransform">
<xsl:value-of
select="substring-after($StringToTransform,'"')"/>
</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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--