Android Question Solution to combine xml and xsl files to generate a webview?

DoctorDebug

Member
Licensed User
Longtime User
Hi, not much on the search about this except by reference it seems it is possible using WebViewExtra but I am unable to find instructions for doing it.

Background - converting a web-based c# app that did this using native calls to B4A/B4I.

Thank you
 

DoctorDebug

Member
Licensed User
Longtime User
What is the question?
Is there a way within b4x to format a xml file using a xsl template file and display the result.

Yes I could do the transformation in code but the existing system which does this has worked so well for so long I don't want to code the solution unless it's necessary.

Thank you, Erel, big fan here for a long time
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Can you upload an example of XML + XSLT files?
 

Attachments

  • example.zip
    654 bytes · Views: 77
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Conversion of: https://stackoverflow.com/questions...l-with-xslt-and-display-it-in-android-webview
B4X:
Private Sub TransformXSLT2Html(Xsl As String, Xml As String) As String
    Dim TransformerFactory As JavaObject
    TransformerFactory = TransformerFactory.InitializeStatic("javax.xml.transform.TransformerFactory").RunMethod("newInstance", Null)
    Dim transformer As JavaObject = TransformerFactory.RunMethod("newTransformer", Array(CreateStreamFromString(Xsl)))
    Dim out As OutputStream
    out.InitializeToBytesArray(1000)
    Dim StreamResult As JavaObject
    StreamResult.InitializeNewInstance("javax.xml.transform.stream.StreamResult", Array(out))
    transformer.RunMethod("transform", Array(CreateStreamFromString(Xml), StreamResult))
    Dim b() As Byte = out.ToBytesArray
    Return BytesToString(b, 0, b.Length, "utf8")
End Sub

Private Sub CreateStreamFromString(s As String) As JavaObject
    Dim b() As Byte = s.GetBytes("utf8")
    Dim in As InputStream
    in.InitializeFromBytesArray(b, 0, b.Length)
    Dim stream As JavaObject
    stream.InitializeNewInstance("javax.xml.transform.stream.StreamSource", Array(in))
    Return stream    
End Sub

Not sure that it actually returns html.
 
Upvote 0
Top