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 August 29th, 2006, 08:27 AM
Registered User
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default document('') and xsl from javascript strings

I seem to be having troubles in IE and firefox (with Sarissa - although the example below uses activex msxml) when creating an xsl dom document from a string and using the following xsl from a variable:

<xsl:variable name="widths" select="document('')/*/x:widths"/>
<x:widths>
    <width>201</width>
    <width>208</width>
    <width>102</width>
</x:widths>

<xsl:template match="/">
    --[<xsl:value-of select="$widths"/>]--
</xsl:template>

This above code works with an xsl dom document from a file as the browsers know what base-uri to use - however when I do it from a javascript string I think it takes the html document itself as the base-uri (I was getting a malformed xml error saying "</form> does not match starting tag: <input>". This <input> tag is in my html file not in the xsl - I fixed this error by putting closing tags on the input to make it well formed).

When I run the script in a browser I get the following output:
--{ --[]--}--

When I run the script from any xml file with the stylesheet also from a file I get the correct output:
--[ 201 208 102 ]--

When I run a slightly changed xsl in the browser with:
<xsl:variable name="widths" select="document('test.xsl')/*/x:widths"/>
it'll work but that doesn't solve my problem because the dynamic design file will contain the widths. As a last resort I can extract the widths from various places in the design file


question Does anybody know how to set the base-uri for an xml created from a javascript string, or any other way of getting around the problem?

I need to do it from a string as I'm using xslt to render an xml design document to output another xsl document which I then use to process xml docs from the server.

thanks for your help in advance

Alex





here's my javascript code for IE:

<span style='font-family:courier'>
<html>
<head>
<script type="text/javascript">
var innerText;
if (!document.all)
   innerText = "textContent";
else
   innerText = "innerText";

var xmlString = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="mynamespace">' +
                '<xsl:output method="text"/>' +
                '<xsl:variable name="widths" select="document(\'\')/*/x:widths"/>' +
                '<x:widths>' +
                '<width>201</width>' +
                '<width>208</width>' +
                '<width>102</width>' +
                '</x:widths>' +
                '<xsl:template match="/">' +
                ' --[<xsl:value-of select="$widths"/>]--' +
                '</xsl:template>' +
                '</xsl:stylesheet>';

function parseXml()
{
    var xmlDoc = new ActiveXObject('MSXML2.DOMDocument.4.0');
    xmlDoc.async=false;
    xmlDoc.load("test.xml");

    var xslDoc =new ActiveXObject('MSXML2.FreeThreadedDOMDocument.4.0' );
    xslDoc.async = false;
    xslDoc.loadXML(xmlString);

    // create XSLTemplate object and compile stylesheet into it
    var cache = new ActiveXObject("Msxml2.XSLTemplate.4.0");
    cache.stylesheet = xslDoc;

    var proc = cache.createProcessor();

    proc.input = xmlDoc;
    var result = proc.transform();

    document.getElementById('content')[innerText]= "--{" + proc.output + "}--";
}
</script>
</head>
<body>
<form>
<input type='button' id="someButton" onClick="parseXml();" value="Change content"/>
<input type='text' name='which' value='1'/>
<div id="content">Content here!</div>
</form>
</body>
</html>
</span>

 
Old August 29th, 2006, 08:47 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry, I don't know the answer to this one.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using XML Spy and an XSL document. AjayLuthria XSLT 3 June 12th, 2007 02:43 PM
xsl:result-document instruction bonekrusher XSLT 3 April 12th, 2007 06:01 PM
changing xml document object with javascript stekker XML 3 May 7th, 2006 08:29 AM
javascript: window.open & document.documentElement rockon Javascript 2 February 3rd, 2005 04:36 PM
Creating a html in an xsl document allenatmarc XSLT 2 June 16th, 2004 04:10 AM





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