Call external file from XSL - sql-server

Can we call an external file (xml, Excel or text file) from XSL?
How do I call SQL Server stored procedures through XSL?
All I am trying to figure out is a way to do mappings from source XML to target XML (let's say if the value of mode vehicle is X in the source, I need to translate it to Y in translate XML based on the mapping stored either in an external file or through a SQL Server stored procedure).

XSLT 1 has the document function (https://www.w3.org/TR/xslt-10/#document) to pull in additional XML documents. Beyond that in XSLT 1 you need to look at extension scripts or elements to deal with other sources, such ways depend on the XSLT processor and/or the programming language or platform (e.g. Java or .NET) it is implemented in.
XSLT 2 in addition to the document function has the doc function for dealing with XML input, it has the unparsed-text function (https://www.w3.org/TR/xslt20/#function-unparsed-text) for text formats and collection (https://www.w3.org/TR/xquery-operators/#func-collection) for input collections. As for SQL, as Saxon 9 on Java is probably the XSLT 2 processor used most, it has in its commercial editions an SQL extension http://saxonica.com/html/documentation/sql-extension/.
XSLT 3 adds support for JSON with functions like parse-json (https://www.w3.org/TR/xpath-functions/#func-parse-json) or json-doc (https://www.w3.org/TR/xpath-functions/#func-json-doc) or json-to-xml (https://www.w3.org/TR/xpath-functions/#func-json-to-xml).
In general I wonder why you need XSLT plus a custom mapping format as in my view template based XSLT in the form
<xsl:template match="foo">
<bar>
<xsl:apply-templates/>
</bar>
</xsl:template>
is the way to declare and implement the mapping. However, if you have a custom mapping, then in all versions of XSLT you can use it create XSLT with XSLT and then run the created XSLT to execute the mapping.

Related

How to Extract .owl and save to mysql

I have a file ontobible.owl. how to extract that file and then save data to mysql (because I want display data from ontobible.owl in website). can anyone help me?
edited:
here is my ontobible.owl file (https://teamtrainit.com/ontobible.owl)
i've try open ontobible.owl with sublime text 3 and contains like this
<Verse rdf:about="http://www.semanticweb.org/budsus/ontologies/2021/7/ontobible#HOS5_2">
<verseID>HOS5_2</verseID>
<verse_text>And the revolters are profound to make slaughter, though I have been a rebuker of them all.</verse_text>
</Verse>
<Verse rdf:about="http://www.semanticweb.org/budsus/ontologies/2021/7/ontobible#2CH2_1">
<hasPerson rdf:resource="http://semanticbible.org/ns/2006/NTNames#god_1324"/>
<hasPerson rdf:resource="http://www.co-ode.org/roberts/family-tree.owl#solomon_2762"/>
<verseID>2CH2_1</verseID>
<verse_text>And Solomon determined to build an house for the name of the LORD, and an house for his kingdom.</verse_text>
</Verse>
how to convert that xml tag to array or json so I cant save it to mysql database
you have several options for extracting data from owl
use owl-api and write java code (i think owl api is accessible in other languages) to extract data and pack it in the format you need. also you can use sparql queries for extracting data via jena api
install protege, open your file in protege and save it in format json-dl. this format is very similar to the regular json and you can easily transform it for your needs
install fuseki server, add your file and using sparql queries extract data from there
i think that the second option is the easiest for start if you don't want to write queries or code and it won't take long

Query .evtx converted to .xml

Having used evtx_dump.py to convert .evtx files to .xml i seek to learn how to query it using XQuery or whatever helps me datamine the document using BaseX.
At this point whatever i try i can only query the whole document using //Events
When i define a path such as //Events/Event/System/[EventID = '4688'] i get 0 results.
This first query is to simply track all specific EventID matching a specific value.
Being new to BaseX and XQuery i found the documentation hard to apply to this use case.
I looked for tools to help me build an XQuery to no avail.
BaseX has all index features enabled i could find.
Br,
Joris
When XQuery fails to return data you are expecting it is often caused by the presence XML namespaces.
The Microsoft XML event log uses a XML namespace on Event nodes and it is inherited by their children. This is the xmlns='http://schemas.microsoft.com/win/2004/08/events/event' you can see in the files. E.g
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Events><Event xmlns='http://schemas.microsoft.com/win/2004/08/events/event'>
<System><Provider Name='SideBySide'/><EventID Qualifiers='49409'>59</EventID><Version>0</Version>
...
Your XQuery must adjust for that. Either by saying any namespace is ok (using *:)
//*:System/[*:EventID = '4688']
or by explicitly specifing the expected namespaces.
declare namespace ns="http://schemas.microsoft.com/win/2004/08/events/event";
/Events/ns:Event/ns:System[ns:EventID= '4688' ]
See this similar issue xquery-not-working-with-namespaces

C program to filter elements of type anyURI from string XML using XSLT

I have a XML string, I want to apply XSLT string on this XML to filter elements of type anyURI.
I am interested to use libxslt. But It transforms the xml present in file. I want to transform xml string.
How to write a C program to transform this xml string?
In terms of XSLT, libxslt is an XSLT 1.0 processor so it doesn't support W3C schema types like xs:anyURI in XSLT, you would need to use an XSLT 2 or 3 processor. Therefore I am not sure how you expect your XSLT program, whether you have it in a file or in a string, to filter out elements of type xs:anyURI.
In terms of C, I guess, depending on your "string" representation, you need to use http://www.xmlsoft.org/html/libxml-parser.html#xmlReadMemory or xmlReadDoc to get an http://www.xmlsoft.org/html/libxml-tree.html#xmlDocPtr for both the XML "string" input and the XSLT "string" input and then the libxslt APIs allow you to use http://xmlsoft.org/XSLT/html/libxslt-xsltInternals.html#xsltParseStylesheetDoc to get an xsltStylesheetPtr and then to run xsltApplyStylesheet.

Convert XML to JSON in C language [duplicate]

I've been searching to no avail for a set of routines to do conversion between JSON and XML. I have found such routines in Javascript, Java, PHP, and Python, but not in C or C++.
FWIW, my json library is json-spirit. I am currently processing JSON, and would like to add XML support via a conversion layer (convert incoming messages from XML to JSON, process them, convert results back to XML, and them out).
Does anyone have any pointers?
I've also seen a number of references to badgerfish, rayfish, rabbitfish... encoding conventions, but they seem to point to dead URLs. Is there a reference somewhere which describes each convention?
And yes, I've checked on json.org.
By far, the only specifically designed C++ library that directly converts XML to JSON I found on the Internet is xml2json: https://github.com/Cheedoong/xml2json
You can also convert JSON to XML if following the same rules.
Boost.PropertyTree handles both JSON and XML. There are some quirks in their implementations, so it wouldn't be a direct transformation, but it shouldn't need much work to adapt a property_tree between JSON and XML.
You could write a xslt for your xml document to convert to json. But I see no standard jslt for converting json.

Decoding the xml to html content from t sql xml column

Earlier,In TSQL we have an XML column to store the html data with xml serialization.
But now we think to keep the html content in CDATA region.
How can I convert the existing xml serialized content to the corresponding html content?
e.g. XML serialized column data : <Node Txt="<b>bold text</b>" />
Expected corresponding transform : <Node><![CDATA[<b>bold text</b>]]></Node>
The above transformation is expected to be carried over by sql script.
I think of a solution to replace all those 5 xml special chars corresponding replacement characters (&,<,>,",etc.). But I dont think string manipulation may work in xml to html transformation.
Any cleaner way or idea to transform those existing xml to html data?
Maybe use the PHP function htmlspecialchars to translate it. If it's a one time thing, this shouldn't be too much trouble for you.
If not, you could code something up using SQL string functions. http://msdn.microsoft.com/en-us/library/ms186862.aspx

Resources