use javascript (or JQuery) in a standalone HTML file to select an XML and transform - xslt

I need a way to transform XML to HTML (using XSL) but without a server. So, I want to create a standalone HTML file (with hardcodes XSL path and name).
Allow the user to select an XML
Transform it with the XSL and display results in browser
Original XML cannot be changed (so cannot just embed XSL in XML)
Is this possible? Everything I found requires post, but I'm not using a server
Regards
Mark

Yes, it's possible. And you don't need javascript to do it, but you can use javascript if you want.
Just look at the previous (XSLT question)[https://stackoverflow.com/questions/12964917]
Use a processing-instruction like...
<?xml-stylesheet type="text/xsl" href="soccer.xslt"?>
Refer:
Direct linkage through pi: http://www.w3.org/TR/xml-stylesheet/
Transform through javascript:
http://dev.ektron.com/kb_article.aspx?id=482
Calling XSLT from javascript

Related

Eliminate javascript from HTML with XSLT

I am trying to transform an HTML report into XML, but some javascript in the file is throwing errors, due to statements with a less-than character (e.g., for(var i=0; i<els.length;i++) ). I thought I could eliminate the javascript with the following template, which should remove entire script nodes:
<xsl:template match="script"/>
I assumed the XSLT processor would simply skip over the entire script nodes, but it's still throwing the same errors. I also tried adding this one:
<xsl:template match="script/text()"/>
No luck. If I manually remove all the javascript from the file, my transform works, but that's not practical as I need to create and run a daily automated process on these HTML files to extract some data in the HTML tables.
As a general rule, XSLT will only process well-formed XML input: it's not designed to process other formats like HTML.
However, XSLT will generally accept input from a parser that delivers a stream of events that looks sufficiently like an XML stream. This allows parsers like TagSoup and validator.nu to be used as a front-end to your XSLT processor.
Saxon packages this up with a parse-html() function that invokes TagSoup to parse HTML input and turn it into a DOM-like tree (actually an XDM tree) that it can process as if it came from XML.
validator.nu is a more up-to-date HTML parser than TagSoup, but you would have to do a little more work to integrate that.
Question was answered by Martin Honnen in the comments:
oxygenxml.com/doc/versions/18.1/ug-editor/tasks/… suggests there is an HTML import feature so try whether that helps. Of course there are standalone applications like HTML Tidy I think you can use outside of the XSLT processsing to first convert your HTML to XHTML.

How to convert/replace mapper activity in TIBCO BW into separate XSLT file?

I am trying to convert Mapper activity of TIBCO BW into a separate XSLT i.e. removing the whole code and using XSLT in place of that.
IS there any easy and fast way to do this as long xslt files are hard to validate.
While in the mapper (select of field), type ctrl-c (copy).
Use ctrl-v (paste) in any text editor to get the XSLT file equivalent.
For use of this XSLT in BusinessWorks, you can use a XSLT Transformation and include either the text itself (in input) or link the file.
See page 322 in the Palette documentation.

Is it possible to generate both HTML and Wiki markup at the same time using XSLT?

I would like to generate both HTML and Wiki markup at the same time using XSLT (from an XML source document) - just wondering if it's possible. It would be nice if I could use the same XSLT to do both rather than writing/maintaining two separate files.
The HTML report will be for general viewing, and the Wiki markup will be published to Confluence.
If you want to create more than one result document using a single stylesheet than XSLT 2.0 and later support that using xsl:result-document, see the specification http://www.w3.org/TR/xslt20/#creating-result-trees. As you then want to process the same elements twice, you usually also make use of modes to separate the different processing, e.g. use one mode to produce HTML, the other mode to produce Wiki markup.
With pure XSLT 1.0 you can only create a single result document, however, some XSLT 1.0 processors, like Xalan (http://xml.apache.org/xalan-j/extensions_xsltc.html#redirect_ext) or xsltproc (http://exslt.org/exsl/elements/document/index.html) support an extension to create more than one result document.

tibco xslt not accepting html script

I have to convert one xml to html page. I read that xml and mapped to transform xml. I have added html formatting tags in xslt. But it is not reflecting in page. I am getting data of xml in one line side by side. The html code not working what i have given. So any one can let me know how to transform xml to html, is there any other solution ?
yes, I have added that "tibco xslt " in title of this question ....
when working on tibco bw, I have to convert xml into html webpage; so i have used html code along with xslt transformation in xslt activity and also referenced it in transform activity. but the resulting html is not as required, all the elements of xml are coming in html side by side;
but when i used this same html code out side of tibco, it is working fine as it is showing in a well formatted table.....
Then my question is will tibco xslt execute html code or not ?
I am not too sure about using xslt transform activity for parsing a xml into html file.
Try parsing xml and then write file activity . You can alter the content of the file as per your requirement with tags and data from the parsed xml file.

Include user control .ascx into xslt

I've created .ascx user control and I'm trying to find a way for including it into xslt rendering. How can I do this? I'm doing it for Sitecore. I thought maybe create a placeholder, but placeholders cannot be defined in renderings. I appreciate any help you can provide.
It's not possible to include ASCX file into xslt file because: XSLT transforms XML to HTML or to XML or to plain text but not to ASP.NET pages.
You can include xslt file into ascx but not ascx into xslt file. The best way is to change your xslt file into ascx file, and to include there with placeholders or directly .
I'd suggest to avoid using XSLT.
They seem pretty easy to use, but it's really hard to refactor the code.
Well, it's not possible to call user controls(.ascx) directly from XSLT files. However depending upon what you want to achieve, you can call .net methods, called XSLT extension methods, from XSLT file. For instance, you may need to write code similar to below to call custom .Net GetData() method.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:customObject="urn:yourNamespace">
<new-data>
<xsl:value-of select="customObject:GetData()"/>
</new-data>
...
Of course the type needs to be registered before it can be used. Type registration can be done into web.config or dynamically by calling AddExtensionObjectMethod of XSLTArgumentList class.
Sitecore offers XSLT extension controls too and unlike extension methods, it isn't a .net feature. XSL extension controls are XML elements in XSL renderings that correspond to .NET classes. For example, the XSL extension control corresponds to the
Sitecore.Web.UI.XslControls.Text .NET class. It will be consumed something like this in XSLT file:
XSL extension controls are standalone elements in the XSL code.
To register a custom type, add following to element in web.config:
<extension mode="on" type="NamespaceName.ClassName, AssemblyName" namespace="http://www.w3.org/1999/XSL/Transform" singleInstance="true"/>
Reference: http://sdn.sitecore.net/upload/sitecore6/64/presentation_component_xsl_reference_sc62-64-a4.pdf