473,958 Members | 15,296 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ajax ?xml-stylesheet

When I use Ajax to load in an xml document (text/xml) it has these
directives :

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/xsl/result.xsl"?>

at the top of the .xml file.

Can anyone explain how to obtain the href xsl as a string from the
returned xmlhttprequest object or response object? I have tried
everything that looks obvious but the root element is the start of my
xml document, and the ?xml are not in the call headers. Close to
banging my noggin on the desk here.

The only other way I can obtain the .xsl reference is by stripping the
header in a Java servlet and making 2 calls and then a 3rd call to load
the .xsl file.

May 17 '06 #1
2 2052


Kenpatchi wrote:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/xsl/result.xsl"?>

at the top of the .xml file.

Can anyone explain how to obtain the href xsl as a string from the
returned xmlhttprequest object or response object?

The <?xml-styleheet?> in terms of the DOM is a processing instruction
node of nodeType 7. It is a direct child node of the document node
itself. The part
type="text/xsl" href="/xsl/result.xsl"
is available as
node.data
meaning you need to parse out the href value yourself from the data
string. Here is an example function doing that

function getStylesheetHr ef (xmlDocument) {
var child;
for (var i = 0, l = xmlDocument.chi ldNodes.length; i < l; i++) {
child = xmlDocument.chi ldNodes[i];
if (child.nodeType == 7 &&
child.target == 'xml-stylesheet')
{
var match, href;
if ((match = /href=["']([^"']*)["']/.exec(child.dat a)) &&
(href = match[1]))
{
return href;
}
}
}
return '';
}

So you could do e.g.

var href = getStylesheetHr ef(httpRequest. responseXML);

and in your example the variable href then has the string value
'/xsl/result.xsl'. If no xml-stylesheet child is found then the empty
string is returned.
--

Martin Honnen
http://JavaScript.FAQTs.com/
May 17 '06 #2
Martin Honnen wrote:
Kenpatchi wrote:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/xsl/result.xsl"?>

at the top of the .xml file.

Can anyone explain how to obtain the href xsl as a string from the
returned xmlhttprequest object or response object?


[...]
function getStylesheetHr ef (xmlDocument) {
var child;
for (var i = 0, l = xmlDocument.chi ldNodes.length; i < l; i++) {
child = xmlDocument.chi ldNodes[i];
if (child.nodeType == 7 &&
child.target == 'xml-stylesheet')
{
var match, href;
if ((match = /href=["']([^"']*)["']/.exec(child.dat a)) &&
(href = match[1]))
{
return href;
}
}
}
return '';
}

So you could do e.g.

var href = getStylesheetHr ef(httpRequest. responseXML);

and in your example the variable href then has the string value
'/xsl/result.xsl'. If no xml-stylesheet child is found then the empty
string is returned.


You could instead do something along

var href = httpRequest.res ponseXML.styles heets[0].href;

See
<URL:http://www.w3.org/TR/DOM-Level-2-Style/stylesheets.htm l#StyleSheets-StyleSheet-DocumentStyle>
PointedEars :)
--
This is Usenet. It is a discussion group, not a helpdesk. You post
something, we discuss it. If you have a question and that happens to get
answered in the course of the discussion, then great. If not, you can
have a full refund of your membership fees. -- Mark Parnell in alt.html
May 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4339
by: bobzimuta | last post by:
I'm creating a simple AJAX library. It's an object that will return an array containing the response text or xml. I'm trying to find a way to assign the response as a property of the object, but from within an inline function. Within the AJAX object: this.xmlhttp = new XMLHttpRequest(); this.response = ''; //to contain the response text OR xml var that = this; //since we cannot reference this within the
0
1857
by: melledge | last post by:
Ajax Developers' Day added to XTech 2006 agenda XTech 2006 - 17-19 May - Hotel Grand Krasnopolsky - Amsterdam, The Netherlands
0
1863
by: melledge | last post by:
Ajax Developers' Day to Kick Off XTech 2006 Conference Industry experts offer insight into next generation of the Web ALEXANDRIA, VIRGINIA, USA - April 25, 2006 - In response to the rapidly developing world of Ajax user interfaces on the browser, IDEAlliance (www.idealliance.org) announced today that its annual XTech Conference will kick off on May 16 with Ajax Developers' Day. XTech 2006 (www.xtech-conference.org), to be held May...
3
2787
by: BG Mahesh | last post by:
hi We are looking for a good Ajax library which has very good support for iframe. The ones we have considered so far are, Backbase.com - not happy with the speed Zapatech.com - it is good but doesn't have support for iframe openreco.org - it is good but doesn't support iframe Any pointers is appreciated. We are doing the development on Linux.
23
5063
by: Allan Ebdrup | last post by:
I hava an ajax web application where i hvae problems with UTF-8 encoding oc chineese chars. My Ajax webapplication runs in a HTML page that is UTF-8 Encoded. I copy and paste some chineese chars from another HTML page viewed in IE7, that is also UTF-8 encoded (search for "china" on google.com). I paste the chineese chars into a content editable div. My Ajax webservice compiles an XML where the data from the content editable div is...
17
11906
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);" onclick="show('ajaxrequest.php?action=removefield','div1');show('ajaxrequest.php?action=reloaddiv2','div2')">verwijderen</a> While both seperate actions work they dont when I put them together. Anyone know how to fix this ? My ajax.js with funcition show
6
4987
by: santhoskumara | last post by:
How to request to servlet from Ajax and also I got the DOM object in the servlet through Business Logic. Now how will i pass the DOM object from serlvet to Clientside. Where in the client Side i am using Ajax. kindly advice me.
0
7201
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along the way. First, deep linking is not something that a completely AJAX web site should be able to do by it's very nature of everything being on one page basically. So how can a person deep link to something that is on one page? This question...
0
5391
by: crocodilu2008 | last post by:
JSON vs. XML JSON and XML are basically used for the same purpose—to represent and interchange data. I'll try to show you why you might want to use JSON rather than XML in an AJAX context by showing you an example of how an data class (actually, a list of PHP documentation pages) might be represented, first in XML. and then in JSON. This side-by-side comparison should let you begin to understand how to represent data in JSON. The XML version:...
0
10255
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11697
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11314
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11464
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10789
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9986
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8363
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7521
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
5049
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.