Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

brunocampos_

[Resolvido] Problema com transform XSL no firefox quando tem # no link

Recommended Posts

Opas,

 

Estou tendo um problema para transformar um XML com XSL no Firefox utilizando o XSLTProcessor.

O firefox apresenta alguns BUGs com relação ao XSLT(alguns inclusive com status de WONTFIX[ridículo isto]), mas este não achei na lista de bugs.

 

 

É o seguinte, eu consigo transformar o XML normalmente, mas quando coloco o símbolo # na barra de endereços da pau. Alguém já passou por isto?

 

Tenho algumas imagens para ajudar a entender:

Imagem Postada

Imagem Postada

Imagem Postada

 

A primeira imagem mostra as telas do firefox antes e depois de clicar no botão. Se olharem o link lá em cima, verão que quando tem o #pp no link, da pau. As duas outras são os códigos. Eu utilizo um framework para fazer esta transformação. O código que faz isto no framework é o seguinte:

var vv = new DOMParser();
						var xsl2 = vv.parseFromString(xslrequest.XSLResponse, "text/xml").documentElement;
						var xml2 = vv.parseFromString(xslrequest.XMLResponse, "text/xml").documentElement;
						var xslp = new XSLTProcessor();
						if(xslrequest.Parameters!=null) {
								for(var i=0; i<xslrequest.Parameters.Values.length; i++) {
										xslp.setParameter(null, xslrequest.Parameters.Values[i][0], xslrequest.Parameters.Values[i][1]);
								}
						}
						xslp.importStylesheet(xsl2);
						var fobj = xslp.transformToFragment(xml2, document);
						if(xslrequest.Target!=null) {
								try {
										$(xslrequest.Target).removeChild($(xslrequest.Target).firstChild);
								} catch(e) {}
								$(xslrequest.Target).appendChild(fobj.firstChild);

Alguém já passou por isto ou sabe de algo?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Opa!

 

O código é meio grande mas vou postar.

O negócio é que, depurando o código, nas primeiras linhas

 

var xsl2 = vv.parseFromString(xslrequest.XSLResponse, "text/xml").documentElement;
var xml2 = vv.parseFromString(xslrequest.XMLResponse, "text/xml").documentElement;

Exibem o XSL(xslrequest.XSLResponse) e o XML(xslrequest.XMLResponse) separados corretamente.

 

 

 

Já como eu chamo a função está nas figuras acima os códigos das páginas.

O código completo desde o Bind() está aqui:

//drjs.xml.js - Dependencies: ajax
//XSL Functions

var XSLBinder = {
	Apply: function(xslrequest) {
		var str = "";
		if(window.ActiveXObject) {
			var xmlObj = new ActiveXObject("Msxml2.DOMDocument");
			xmlObj.loadXML(xslrequest.XMLResponse);
			var xsltObj = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
			xsltObj.loadXML(xslrequest.XSLResponse);
			var xslTemplate = new ActiveXObject("Msxml2.XSLTemplate");
			xslTemplate.stylesheet = xsltObj;
			var xslProc = xslTemplate.createProcessor();
			if(xslrequest.Parameters!=null) {
				for(var i=0; i<xslrequest.Parameters.Values.length; i++) {
					xslProc.addParameter(xslrequest.Parameters.Values[i][0], xslrequest.Parameters.Values[i][1]);
				}
			}
			xslProc.input = xmlObj;
			xslProc.transform();
			str = xslProc.output;
			
			var re = new RegExp("
","gim");
			str = str.replace(re, "");
			str = str.substr(str.indexOf("?>")+2);		
			xslrequest.ResponseText = str;
			$(xslrequest.Target).SetContent(str);
		} else {
			var vv = new DOMParser();
			var xsl2 = vv.parseFromString(xslrequest.XSLResponse, "text/xml").documentElement;
			var xml2 = vv.parseFromString(xslrequest.XMLResponse, "text/xml").documentElement;
			var xslp = new XSLTProcessor();
			if(xslrequest.Parameters!=null) {
				for(var i=0; i<xslrequest.Parameters.Values.length; i++) {
					xslp.setParameter(null, xslrequest.Parameters.Values[i][0], xslrequest.Parameters.Values[i][1]);
				}
			}
			xslp.importStylesheet(xsl2);
			var fobj = xslp.transformToFragment(xml2, document);
			if(xslrequest.Target!=null) {
				try {
					$(xslrequest.Target).innerHTML = "";
					$(xslrequest.Target).removeChild($(xslrequest.Target).firstChild);
				} catch(e) {}
				$(xslrequest.Target).appendChild(fobj.firstChild);
			}
		}
		if(xslrequest.Callback!=null) {
			xslrequest.Callback(xslrequest);
		}
	},
	Bind: function(xmlRequest, xslRequest, parameters, callback, target) {
		XSLBinderRequestQueue.AddRequest(new XSLBinderRequest(xmlRequest, xslRequest, parameters, callback, target));
	}
};

var XSLBinderRequest = Class.Create();
XSLBinderRequest.AddMethods({
	Callback: null,
	Parameters: null,
	ResponseText: null,
	Target: null,
	XMLRequest: null,
	XMLResponse: null,
	XSLRequest: null,
	XSLResponse: null,
	_constructor: function(xmlRequest, xslRequest, parameters, callback, target) {
		if(typeof(xmlRequest)=="string") {
			this.XMLResponse = xmlRequest;
		} else {
			this.XMLRequest = xmlRequest;
		}
		if(typeof(xslRequest)=="string") {
			this.XSLResponse = xslRequest;
		} else {
			this.XSLRequest = xslRequest;
		}
		this.Parameters = parameters;
		this.Callback = callback;
		this.Target = target;
	}
});

var XSLBinderRequestQueue = {
	currentRequest: null,
	currentRequestDone: 2,	//0-None loaded, 1-Only XML loaded, 2-All loaded, 4-Only XSL loaded
	currentXML: null,
	currentXSL: null,
	posXML: null,
	posXSL: null,
	requests: [],
	AddRequest: function(binderRequest) {	
		this.requests.push(binderRequest);
		this.checkQueue();
	},
	CallbackFunction: function(request, pos) {
		pos = request.Pos;
		if(pos==XSLBinderRequestQueue.posXML) {
			XSLBinderRequestQueue.currentRequest.XMLResponse = request.ResponseText;
			if(XSLBinderRequestQueue.currentRequestDone==0) {
				XSLBinderRequestQueue.currentRequestDone = 1;
			} else if(XSLBinderRequestQueue.currentRequestDone==4) {
				XSLBinderRequestQueue.currentRequestDone = 2;
			}
		} else if(pos==XSLBinderRequestQueue.posXSL) {
			XSLBinderRequestQueue.currentRequest.XSLResponse = request.ResponseText;
			if(XSLBinderRequestQueue.currentRequestDone==0) {
				XSLBinderRequestQueue.currentRequestDone = 4;
			} else if(XSLBinderRequestQueue.currentRequestDone==1) {
				XSLBinderRequestQueue.currentRequestDone = 2;
			}
		}
		if(XSLBinderRequestQueue.currentRequestDone==2) {
			XSLBinder.Apply(XSLBinderRequestQueue.currentRequest);
			XSLBinderRequestQueue.currentRequest = null;
			XSLBinderRequestQueue.checkQueue();
		}
	},
	checkQueue: function() {
		if(this.currentRequest==null) {
			this.nextRequest();
		}
	},
	nextRequest: function() {
		if(this.requests.length>0) {
			this.currentRequest = this.requests[0];
			this.requests = this.requests.removePos(0);
			this.currentRequestDone = 0;
			if(this.currentRequest.XMLRequest!=null || this.currentRequest.XSLRequest!=null) {
				if(this.currentRequest.XMLRequest!=null) {
					this.currentRequest.XMLRequest.Callback = this.CallbackFunction;
					this.posXML = AjaxRequestQueue.AddRequest(this.currentRequest.XMLRequest.Copy());
				} else {
					this.currentRequestDone = 1;
				}
				if(this.currentRequest.XSLRequest!=null) {
					this.currentRequest.XSLRequest.Callback = this.CallbackFunction;
					this.posXSL = AjaxRequestQueue.AddRequest(this.currentRequest.XSLRequest.Copy());
				} else {
					this.currentRequestDone = 4;
				}
			} else {
				XSLBinderRequestQueue.currentRequestDone==2;
				this.CallbackFunction(null, -1);
			}
		}
	}
};

var XSLParameters = Class.Create();
XSLParameters.AddMethods({
	Values: [],
	_constructor: function() {
		this.Values = [];
	},
	AddParam: function(name, value) {
		this.Values.push([name, value]);
	}
});

drjs.loadComplete(drjs.files.xsl);

Compartilhar este post


Link para o post
Compartilhar em outros sites

Entao.. n averdade eu pedi para você postar como você CHAMA a função.. ou seja... se você a chama no evento onClick de um link, ou botao, ou a chama de outro jeito...

 

Entendeu ??

 

Abraços..

Compartilhar este post


Link para o post
Compartilhar em outros sites

Pelo que pude perceber, você tem um "<a name = "pp"> no seu código.... ou seja.. você está utilizando algum tipo de ancora...

 

No link que chama essa ancora, coloque um "return false;" dentro do onClick dele... assim o "#pp" nao aparecerá na url.. e sua função vai de boa...

 

Abraços...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Opa! Valeu pela resposta.

 

Não tem link que chama a ancora, eu não estou tentando chamar a âncora.

Na verdade eu estou tendo este problema em uma página sem âncora, porém coloquei ela lá só para mostrar que o problema não é por não achar a ancora na página.

 

Como na figura 1, se eu acesso a página http://aaa.com/testexsl.aspx, me aparece um botão na página.

Eu clico no botão e OK, o texto é alterado.

Já se eu acesso a página http://aaa.com/testexsl.aspx#pp (digito isto na URL), acontece a mesma coisa, aparece o botão lá.

Eu clico no botão e o texto é alterado para meu XML. Não acontece a transformação. Só por ter o # lá na URL.

 

E eu preciso do # na URL, pois a finalidade disto é conseguir bookmarks e controle de histórico em uma aplicação com ajax. Seria algo tipo as URLs do GMail.

 

 

 

 

 

 

Não sei se você ou alguém tem acesso, mas eu postei esta dúvida também em

http://www.experts-exchange.com/Web_Develo...Q_23178983.html

Vou postar o histórico de lá aqui, mas é grande e acho que não é nescessário ler para entendimento, vou deixar apenas para histórico.

No caso Alex sou eu e Abel quem estava tentando me ajudar.

 

 

Hi,

 

I am developing a page that needs to transform a XML and a XSL into HTML.

The code is working fine, at both Internet Explorer and Firefox.

But if my page location has an anchor on it(eg. www.site.com/#myanchor), it stops working at Firefox.

 

The code is just below, at the Code Snippet Box.

 

As I said, it works fine on both browsers, but just without anchors at link. So if I type www.mysite.com/ at my browser, it works fine.

But if I type www.mysite.com/#omg, it doesnt work in firefox.

 

 

Can anyone help?

 

Thanks in advance.

Hi Alex,

 

We'll need a little bit ore information to help you with this. I.e.:

 

- Is the anchor located in the part you created with XSLT or in the part that is static?

- If you say "it" doesn't work, what do you mean with "it": the XSLT transformation or the browser going to the anchor on the page?

- If the anchor is created with XSLT, can you show the relevant parts of the XSLT (or the XSLT in full)?

- You refer specifically to firefox, what is the expected behavior and does that work well in IE, Opera etc?

- How do you invoke the script above: through a (click) event, on other user action (i.e., typing a text), or on loading the page?

- Are there other builder scripts that may create or destroy the anchor?

 

Please update so that I / We can help you further.

 

Cheers,

-- Abel --

Hi Abel,

 

thanks for your help. Answering your questions:

 

1- There is no anchor(<a name="">) in the page. The problem is when I put the # in the URL. I use that to do history control with ajax

2- What doesnt work is the XSL transformation when there is a # at the URL

3- The XSLT doesnt create anchors, there are no anchors in the HTML

4- Didnt tested it at Opera yet, but it works fine at ie

5- I invoke the script at the onload page, but tested it with the onclick event either. There is a engine that verifies the URL typed at the browser and load that fragment inside a div. For example, if the user type www.mysite.com/#Alex, it loads data about alex inside a div in the page. If the user type www.mysite.com/#Bruno it loads data about Bruno(something similar to the GMail history control)

6- No

 

 

I made a simple page to teste that behavior with the onclick event(example.aspx was the name of the page).

The XSL transformation was working fine. But if I access the page passing an anchor name to it(example.aspx#Alex), it stops working at firefox. Even if I put a <a name="Alex></a> at the page.

Hi Alex,

 

Hmm, I'm thinking of a couple of causes that might be the result of the behavior you are experiencing, but none seem to be a total fit to your story. However, before I try to completely reproduce your problem locally, I have a couple of things I like to share with you about your current design, provided I understand your tellings well enough.

 

Using an anchor to control the history (you mean the cache of the browser? Or do you mean the back-browse feature of a browser to accommodate for history problems in dynamic AJAX applications?) is a debatable use of the anchor. An anchor is meant to instruct the browser and it will, for instance, not instantiate a new load of the same page. Instead, it will try to locate the element with id="#anchor", or an element <a name="anchor"></a> and scroll there.

 

As an alternative and possibly as a better solution (i.e. to re-invoke the onload) you should consider using the querystring instead (i.e, any part behind the question mark on the link, like http://example.com/test?div=Bruno). A query string is easier to locate does not give any side effects, apart from a browser visit to the server of course.

 

If the latter is a problem, there are sufficient other solutions, like passing parameters to and from the XSLT to pass on information, but to help you there I need to understand your project a bit more.

 

Regardless, this won't change the situation (seemingly) that once you have an anchor the XSLT seems to break, even when in an onclick (I understand the onload fails, but the onclick???). I'll have to try that out, because I am sure I have dozens of pages that fit the description of your problem with XSLT, anchors, queries etc, without any problem whatsoever.

 

One more question left unanswered: do you get any errors or is the script not invoked at all? At what line in your code above (or your own code) does it stop working? Can you check the JavaScript console on Firefox?

 

Cheers,

-- Abel --

Hi Abel,

 

 

The History Control is meant to enable the back-browser feature and bookmarks.

 

I can't use the query string, because the page can't be entire loaded again. (and I don't know a way to use the query string in the url and don't load the entire page again, is that possible?)

 

The Javascript console doesn't return any errors at all.

 

I am posting some images to show whats happening. The window.jpg file shows 4 Firefox screens, 2 without the anchor on the link, and 2 with it. As you see, in the second case, the firefox doesnt transform my xml, and just show it.

The other 2 images are codes. I use a framework to do this, and the code part of the framework that transforms the xml is at the code snippet box.

 

Thanks for helping.

 

-----

E aqui entram as imagens...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bom.. pelo que percebi no seu dialogo "gringo" ( sim, DarkDemo tb fala "inglish" IUAHiuHAIuhuiHAUiIAuiHA ) o Abel te fez as mesmas perguntas e teve quase o mesmo raciocinio que eu...

 

POREM, eu nao manjo NADA de Dot Net, e você está utilizando um frameWork, nao vou poder te ajudar muito nesse caso...

 

Bom.. eu tentei.... mas ainda acho melhor você postar isso na area de DOt Net, ou pedir a algum Modera daki mover ele pra lá..

 

Mal nao poder te ajudar cara.... =/

 

Abraços...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Hehe de boa, já faz dias que está sem resposta lá também(e costuma ser muito rápido [questão de poucos minutos], pois lá as pessoas ganham para responder)...

Ele não estava entendendo a pergunta, então quando postei as imagens ele não sabia o que poderia ser.

 

Mas não tem a ver com .Net, pode ser uma página HTML qualquer.

O framework é apenas js e foi feito por mim mesmo, portanto é tranquilo eu mudar qualquer coisa. Já até tentei colocar algumas partes no código da página mesmo.

O estranho é que da errado apenas por colocar o # na URL da página. Sem o # tudo funciona muito bem.

 

Valeu pelas respostas

Compartilhar este post


Link para o post
Compartilhar em outros sites

Manda todos os arquivos pro meu e-mail por favor, assim posso analisar melhor...

 

Se você puder me mandar em HTML mesmo....

 

Abraços..

 

PS: Meu e-mail te mando por mp..

Compartilhar este post


Link para o post
Compartilhar em outros sites

Resolvi o problema. Achei este BUG na lista.

Acho que é o 3o dessa semana do FF que me encomoda :P

 

Aqui discutem o BUG e apresentam soluções(é uma pequena gambiarra para enganar o XSLTProcessor)

https://bugzilla.mozilla.org/show_bug.cgi?id=212362

 

 

Aqui é a página principal do BUG

https://bugzilla.mozilla.org/show_bug.cgi?id=355068

 

 

Tinha até um test case onde dá para mostrar o BUG em ação:

https://bugzilla.mozilla.org/attachment.cgi?id=290460

https://bugzilla.mozilla.org/attachment.cgi?id=290460#bruno

 

 

Diz estar resolvido mas pelo jeito está em testes ainda, ou deve estar nas versões beta.

Estou sem tempo para ficar baixando versões do FF para testar, mas pelo menos até a 2.0.0.12 está bugado isto.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.