You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Daya Sharma <da...@mongoosetech.com> on 2002/06/24 22:49:09 UTC

Escaping ' during transformation with xerces2.0.1 throws TransformerException: misquoted literal... expected single quote!

Hi All


I have the following stylesheet which outputs HTML. but in the output I see
&apos; in the text instead of "'" the actual apostrophe.

So to counter that I use a called template which would search and replace
&apos; with "'" apostrophe. But I can't it to work


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
	<xsl:output method="html" omit-xml-declaration="yes" indent="yes"/>

	<xsl:template name="SEARCH-AND-REPLACE">
		<xsl:param name="string" />
		<xsl:param name="search-for" />
		<xsl:param name="replace-with" />
		<xsl:choose>
			<xsl:when test='contains($string,$search-for)'>
				<xsl:value-of
select="substring-before($string,$search-for)"/>
				<xsl:value-of select="$replace-with"/>
				<xsl:call-template name="SEARCH-AND-REPLACE">
					<xsl:with-param
						name="string"
	
select="substring-after($string,$search-for)" />
					<xsl:with-param name="search-for"
select="$search-for" />
					<xsl:with-param name="replace-with"
select="$replace-with" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$string" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

<xsl:template match="/MergedDocuments/moreovernews/article">
	<xsl:if test="$numberOfArticlesPerCategory > 0">
		<xsl:if test="$numberOfArticlesPerCategory >= ((position())
div 2) ">
			<tr>
				<xsl:variable name="url">
					<xsl:value-of
select="normalize-space(url)"/>
					</xsl:variable>
					<xsl:variable name="headline">
					<xsl:value-of
select="normalize-space(headline_text)"/>
					</xsl:variable>
					<td colspan="2"
style="padding-top:4px" width="100%">
						<a class="primaryLink"
target="_new">
							<xsl:attribute
name="href">
								<xsl:value-of
select="$url"/>
							</xsl:attribute>
							<xsl:call-template
name="SEARCH-AND-REPLACE">
							<xsl:with-param
name="string" select="$headline" />
							<xsl:with-param
name="search-for" select="&apos;"/>
							<xsl:with-param
name="replace-with" select="'" />
							</xsl:call-template>
						</a>
					</td>
				</tr>
	</xsl:template>
</xsl:stylesheet>


But I get this exception 
javax.xml.transform.TransformerException: misquoted literal... expected
single quote!    
when I transform the following xml
<moreovernews>
    <article id="_41104493">
        <url>http://c.moreover.com/click/here.pl?x41104493</url>
        <headline_text>Starkville&apos;s Miss USA loving every moment
6/23</headline_text>
        <source>Starkville Daily News</source>
        <media_type>text</media_type>
        <cluster>moreover...</cluster>
        <tagline/>
        <document_url>http://www.zwire.com</document_url>
        <harvest_time>Jun 24 2002 1:07PM</harvest_time>
        <access_registration/>
        <access_status/>
    </article>
</moreovernews>

Can somebody please tell me how can I make the &apos; not show up in the
browser

thanx in advance

daya sharma

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org