Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 20th, 2006, 11:22 PM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Quotes corrupts text-to-speech

Hi,
I am using an RSS feed to create a paragraph of news headlines (within an ASP page) that is then processed as text-to-speech. Everything is fine until the feed contains quotation marks which corrupts the formatting for the text-to-speech. Apostrophies are ok.

I have tried experimenting with 'translate', but my knowledge of XSLT is miniscule and I would be very grateful for any suggestions.

Below is the XSL code followed by the ASP:

Code:
<?xml version="1.0" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" encoding="iso-8859-1" omit-xml-declaration="yes" indent="yes"/> 
<xsl:template match="*"> 
<xsl:for-each select="//*[local-name()='item']"> 
<xsl:if test="position() &lt; 7">
<xsl:value-of select="*[local-name()='description']" disable-output-escaping="yes"/> 
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each> 
</xsl:template> 
<xsl:template match="/"> 
<xsl:apply-templates/> 
</xsl:template> 
</xsl:stylesheet>


<%
Sub getXML(sourceFile)
     dim styleFile
     dim source, style
     styleFile = Server.MapPath("news2.xsl")

     set source = Server.CreateObject("Msxml2.DomDocument")
     source.async = false
     source.setProperty "ServerHTTPRequest", true
     source.load CStr(sourceFile)

     set style = Server.CreateObject("Msxml2.DomDocument")
     style.async = false
     style.load styleFile

     source.transformNodeToObject style, Response
     set source = nothing
     set style = nothing
End Sub
%>
Cheers,
Ben
 
Old March 21st, 2006, 05:06 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I've no idea where in your code you want to replace quotes by apostrophes so I can't help you with the immediate question. But I can make some general comments about your code, which you might find helpful.

<xsl:output method="xml" encoding="iso-8859-1" omit-xml-declaration="yes" indent="yes"/>

Is your stylesheet really producing XML? As far as I can see, it only produces text. In that case, use method="text". Producing XML and then trying to suppress its inherent XML features by using "omit-xml-declaration" and "disable-output-escaping" isn't the right way to do it.

<xsl:template match="*">
<xsl:for-each select="//*[local-name()='item']">

In a template that matches every element, it's usually wrong to then use select="//*" which selects everything. In this case I think you're only invoking the template to match the outermost element, in which case the logic might as well go in the match="/" template.

The actual selection //*[local-name()='item'] suggests you are ignoring namespaces. That's normally not recommended practice - but because RSS namespaces are such a disaster area, it's understandable.

<xsl:value-of select="*[local-name()='description']" disable-output-escaping="yes"/>

Presumably this is where you want to translate quotes to apostrophes?

Try

<xsl:variable name="quot">"</xsl:variable>
<xsl:variable name="apos">'</xsl:variable>

<xsl:value of select="translate(*[local-name()='description'],
$quot, $apos)"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 21st, 2006, 07:43 AM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Michael you are an absolute star! :D

Thank you very much, it works fine now:

http://www.blackice.co.uk/news.asp

Cheers,

Ben






Similar Threads
Thread Thread Starter Forum Replies Last Post
Text to Speech using Java Script on Windows XP sreek_s Other Programming Languages 2 December 23rd, 2007 01:05 PM
displaying single quotes and double quotes ren_123 Classic ASP Databases 2 February 22nd, 2006 02:17 PM
Double Quotes and Single Quotes Problem phungleon Classic ASP Basics 7 May 27th, 2004 01:44 PM
Storing single and double quotes in text roniestein Access 4 December 30th, 2003 05:09 PM
Help with Text-to-Speech vb_programmer Pro VB 6 0 September 24th, 2003 11:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.