开发者

Display XSL Formatted XML on a Control

I have XML files formatted with XSL. They look great on IE.

Now how do I do the same with Flex (not AIR)? I would like to use something like TextArea a开发者_运维百科nd not data grid.

Thanks.


I think I can use JavaScript to do the transformation. So my Flex application passes the XML and XSL URLs to a JavaScript. The JavaScript does the XML-XSL transformation. And it should pass the transformed HTML back to Flex, so my Flex application can popup a TextArea (or similar) to display it.

I think I am getting close. But the problem at the moment is, the transformed HTML seems to be null/empty. Any ideas?

function loadXMLDoc(dname)
{
  if (window.XMLHttpRequest)
  {
    xhttp=new XMLHttpRequest();
  }
  else
  {
    xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xhttp.open("GET",dname,false);
  xhttp.send("");
  return xhttp.responseXML;
}

function displayResult(xmlURL, xslURL) 
{
  //prepare xml and xsl
  xml=loadXMLDoc(xmlURL);
  xsl=loadXMLDoc(xslURL);

  //get flash
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  var flashName = "index";
  var flashObject = (isIE) ? window[flashName] : document[flashName];

  // code for IE
  if (window.ActiveXObject)
  {
    ex=xml.transformNode(xsl);
    flashObject.GetTransformedHTML(ex); 
  }
  // code for Mozilla, Firefox, Opera, etc.
  else if (document.implementation && document.implementation.createDocument)
  {
    xsltProcessor=new XSLTProcessor();
    xsltProcessor.importStylesheet(xsl);
    resultDocument = xsltProcessor.transformToFragment(xml,document);
    document.getElementById("example").appendChild(resultDocument);
  }
}

Thanks.


I found a solution.

Instead of displaying an XSL-applied XML with a popup (e.g. with IE), I can display it in Flex with a component found here:

http://code.google.com/p/flex-iframe/


Below is a sample, and the important thing here is the line below. We should use toXMLString() function :

CBSPopup.showNotification("stavka : " + stavka.toXMLString());

The rest of the code :

if(children.length() > 0){
                    var idPravila : String = _dataprovider.@IdPravila[0];
                    for each(var child:XML in children ) {
                        var stavka : XML = <entity name="PopustBenzinskeStanice" 
                                            SCCode={child.@SCCode[0]} 
                                            SubcompanyName={child.@SubcompanyName[0]} 
                                            SCCodeMedjusloj={child.@SCCodeMedjusloj[0]} 
                                            IdPravila={idPravila} 
                                        />;
                        CBSPopup.showNotification("stavka : " + stavka.toXMLString());
                        _dataprovider.appendChild(stavka);
                    }
                    //if (poslovneJediniceGrid.dataProvider == null) {
                        poslovneJediniceGrid.DataProvider  = _dataprovider.entity.(attribute("name") == "PopustBenzinskeStanice");
                    //}

                    poslovneJediniceGrid.dataProvider.refresh();
                }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜