Saxon C how to run multiple xslts on a cached xml - c++

I want to run several Xslts with one cached xml . However I can only find ways to run several xml files with
a cachedxslt , but thats not what I want . As well as an XsltExecutable for Xslt , can there be an XsltExecutbale for Xmls, so that i can cache an xml , and run several xslts on it.

You can create a DocumentBuilder and use parseXmlFromFile (https://www.saxonica.com/saxon-c/doc11/html/classDocumentBuilder.html#a4fd6acc79cbed4ae3aa9bd062ffa080f) to parse your XML input file once into an XdmNode, then you can feed that XdmNode as the input to any transformTo... method you call on your XsltExecutable or run any applyTemplates.. method after setting that XdmNode as the initial match selection with the method setInitialMatchSelection.

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.

Can I extract the columns/fields and logic used in an XSLT?

I am specifically looking to parse the XSLT to retrieve the fields in the input XML and also get the logic between the input and output data been generated,
I am not sure, but have i been given a target to create an XSLT parser which is like a sub module in a browser?
It is more like reverse engineer some code to get the source and map it to the destination data.

Generate UUID with timestamp method

I want to transform an xml source into several xml output files where the filenames are based on a guid (f.e "97749654-886A-11E6-1885-09173F13E4C5.xml").
I am using xslt 2.0 and the home edition of saxon, so I can't use randomUUID().
In other posts I found the workaround with the timestamp method.
But it seems that the current-dateTime() stays the same in the transformation. So the transformation errors because the guid and thus the filenames stay the same.
Is there a way to work around this?

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.

Process Multiple input xml files and generate multiple xml files in XSLT

I have to pass multiple input xml files and generate multiple xml files as output.
If 'm having 3 files as 'File1.xml', 'File2.xml' and 'File3.xml',
I need to copy the full content of those xml's and also add a node to each xml and then display the output files as 'File1_op.xml', 'File2_op.xml' and 'File3_op.xml'. The output files will have a extra node added like
<Product>45896</Product>
I can't pass the file names as static, because it may change. So I need to pass the directory itself and process all the xml files in that particular directory.
Is this possible in xslt? Any help please.
Using Saxon XSLT 2.0 you're on the bright side - I don't have this on hand so I can't give detailled help. My suggestions are
for input file names Running a single stylesheet on multiple input documents and placing all their outputs in a single file
for output Why does Saxon evaluate the result-document URI to be the same?