Android Question XSLT to HTML Transformation

realblue

Member
Licensed User
Longtime User
Hi everybody,

I have an e-invoice desktop application which process invoices (send and receive). When an invoice is received it comes in a special XML format which includes an XSLT file (encoded base64) in it. In order to display the invoice the XSLT definition should be extracted from the XML and using the same XML as data should be transformed it into an HTML.

What I need is a similar functionality in B4A. I use the below code in Visual Basic :

B4X:
Imports System.Xml
Private Function TransformXMLToHTML(ByVal inputXml As String, ByVal inputXslt As String) As String
        Dim results As StringWriter = Nothing
        Dim transform As New XslCompiledTransform()
        Dim settings As New XmlReaderSettings()
        settings.ProhibitDtd = False
        settings.ValidationType = ValidationType.None
        Using reader As XmlReader = XmlReader.Create(New StringReader(inputXslt), settings)
            Try
                transform.Load(reader)
                results = New StringWriter()
                Using reader2 As XmlReader = XmlReader.Create(New StringReader(inputXml))
                    transform.Transform(reader2, Nothing, results)
                End Using
            Catch ex As Exception
                Return "Unable to transform : " & ex.Message
            End Try
        End Using
        If results IsNot Nothing Then
            Return results.ToString()
        Else
            Return "Unable to transform"
        End If
    End Function
 
Top