SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    597
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML - XSL to produce VoiceXML ---> One for Kevin Yank

    anyone,


    this is fairly simple (i think).

    what I'm trying to do is a proof of concept...

    I want to have a simple xml file that has employee info be "transformed" into a html file for the net and a voiceXML file for a phone system.
    the html part is simple, got that (actually the book does,
    however, the VoiceXML part has a small glitch that I'm having trouble with.

    [H1]XML FILE[/H1]
    Code:
    <?xml version="1.0"?>
    <employee FullSecurity="1">
    	<name>John Doe</name>
    	<department>Widget Sales</department>
    	<phone>(555)555-5555<extension>2974</extension></phone>
    	<salary>62,000</salary>
    	<area>3</area>
    </employee>

    [H1]XSL 4 XML 2 HTML[/H1]
    Code:
     <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html>
    <head>
    <title><xsl:value-of select="/employee/name"/></title>
    </head>
    <body>
    <h1>Employee: <xsl:value-of select="/employee/name"/></h1>
    <p>Department: <xsl:value-of select="/employee/department"/></p>
    <xsl:if test="number(/employee/@FullSecurity)">
    	<p>Salary: <xsl:value-of select="/employee/salary"/></p>
    </xsl:if>
    <p>Location: <xsl:apply-templates select="/employee/area"/></p>
    </body>
    </html>
    </xsl:template>
    
    <xsl:template match="phone">
    	Phone: <xsl:value-of select="text()"/> x<xsl:value-of select="extension"/>
    </xsl:template>
    
    <xsl:template match="area">
    	<xsl:choose>
    		<xsl:when test=". = '1'">Toronto</xsl:when>
    		<xsl:when test=". = '2'">London</xsl:when>
    		<xsl:when test=". = '3'">New York</xsl:when>
    		<xsl:when test=". = '4'">Tokyo</xsl:when>
    		<xsl:otherwise>Unknown Location</xsl:otherwise>
    	</xsl:choose>
    </xsl:template>
    </xsl:stylesheet>


    [H1]XSL 4 XML 2 VOICEXML
    Code:
     <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/" disable-output-escaping="yes">
    	&gt;!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN"
    	"http://cafe.bevocal.com/libraries/dtd/vxml1-0-bevocal.dtd">
    	&gt;vxml version="2.0" xmlns:bevocal="http://www.bevocal.com/">
    	&gt;form>
    		&gt;prompt>Employee: &gt;/prompt>
    		&gt;prompt><xsl:value-of select="/employee/name"/>&gt;/prompt>
    		&gt;prompt>Works in the department: &gt;/prompt>
    		&gt;prompt><xsl:value-of select="/employee/department"/>&gt;/prompt>
    		&gt;prompt>He works out of: &gt;/prompt>
    		&gt;prompt><xsl:value-of select="/employee/location"/>&gt;/prompt>
    	&gt;/form>
    	&gt;/vxml>
    </xsl:template>
    </xsl:stylesheet>
    the problem is that I have to escape the "<" character since it isn't allowed in XML and I need to somehow convert it back to "<" in the resulting file.


    btw, I'm using XT to work the magic.


    Thanks a million!

    Sam

  2. #2
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    597
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SOLUTION

    I found it.

    Code:
    <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml1-0-bevocal.dtd">
    What I did was add a text XSL function(i don't know naming conventions) which printed out the DTD line for the XML and I had to escape the < at the beginning with &lt;

    this is awesome stuff!

    From one XML file (which can be produced by a database server, like SQL-2000) I was able to produce a HTML and a VoiceXML file. very easy.


    Sam

    btw, I was reading into XSLT at the time that I ran across your article. talk about JIT. (just in time.)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •