Convert large XML files using XSLT

I have a program that outputs reports in HTML format. On average, they are about 5-10 MB, but I have seen extreme cases when they are 500 MB. These reports are purely client, the server is not involved here.

The problem is that the browser will hang until all the content has been downloaded, and sometimes it will not even load the content. I am trying to find a solution when someone who opens a report can always open it. People who open reports should be able to open them using a browser and any technology available in it.

I came up with a solution that would open a report that was previously 100MB, having our XML program output, and then convert it to HTML using XSLT, but the user still needs to wait until everything needs to be loaded into memory. All the content is inside these difference nodes, loaded into 2 rows of the table, and their order does not matter.

XML:

<diff> <parent loc="some string"/> <right> content</right> <left> content </left> </diff> 

XSLT to do this conversion is below:

 <xsl:for-each select="./diff"> <table align="center" border="1px" width="602"> <tbody> <tr> <td colspan="2"><xsl:value-of select="./parent/@loc"/></td> </tr> <tr> <td width="50%" align="left"> <xsl:if test="./left/text()"> <xsl:value-of select="./left/text()"/> </xsl:if> <xsl:if test="not(./left/text())"> <xsl:variable name="left"> <xsl:apply-templates select="./left/*" mode="serialize"/> </xsl:variable> <xsl:value-of select="$left"/> </xsl:if> </td> <td width="50%" align="right"> <xsl:if test="./right/text()"> <xsl:value-of select="./right/text()"/> </xsl:if> <xsl:if test="not(./right/text())"> <xsl:variable name="right"> <xsl:apply-templates select="./right/*" mode="serialize"/> </xsl:variable> <xsl:value-of select="$right"/> </xsl:if> </td> </tr> </tbody> </table> </xsl:for-each> 

I am wondering if there is a way to load the file faster or not wait for the entire table to load into memory before displaying the page.

I donโ€™t want to download the javascript library for this, since we donโ€™t want to worry about connecting when viewing these reports and donโ€™t want to install a bunch of files on all machines, but I can use some script inside xslt.

I know this is a strange scenario, and this is not an ideal way to structure the application, but we donโ€™t have time to change the way these reports are generated.

+4
source share
1 answer

My initial thought is to list the html files directory. Therefore, if we start with

 /supersize500MB.html 

To:

 /container /first10percent.html /second10percent.html /third10percent.html ... 

Then in the HTML that you produce, you can hardcode things like:

 <a href="first10percent.html">Last Page</a> <a href="second10percent.html">Next Page</a> 

XSLT 2.0 has the ability to display multiple documents from a single input. A quick google gave this one . The XSLT processor will have to load all of the input XML into memory, but I assume that the output HTML will play in sequence. The overall effect should be that the browser does not need to download the 500meg source file, but a 50meg snippet for everything.

+2
source

Source: https://habr.com/ru/post/1441851/


All Articles