vb.net - Large XML file - wrap elements inside tags using XSLT or by manipulating the XML as String? -
i have large xml file, around 3-4 mb , need wrap elements inside tags. xml has following structure:
<body> <p></p> <p> <sectpr></sectpr> </p> <p></p> <p></p> <tbl></tbl> <p> <sectpr></sectpr> </p> </body>
of course, p
, tbl
elements repeat inside body
until end of file (also each of elements presented above have children - took them out sake of simplicity). estimate, have around 70 elements containing sectpr
inside body
, not in order described above.
what do, wrap elements starting element containing sectpr
next element containing sectpr
tag. result, xml should this:
<body> <p></p> <mytag> <p> <sectpr></sectpr> </p> <p></p> <p></p> <tbl></tbl> </mytag> <mytag> <p> <sectpr></sectpr> </p> </mytag> </body>
also, requirement operation must performed under 40 seconds.
my question is: think possible achieve result using xslt , if case please provide short description on how can it, or think better read xml file string , add tags manipulating string?
also, programming language, using visual basic.
thank in advance.
another requirement operation must performed under 40 seconds.
performance depends large extent on specific processor in use. if using msxml, may benefit using so-called "sibling recursion" in scenario - as shown dimitre novatchev.
try:
xslt 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" > <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/> <!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="/body"> <xsl:copy> <!-- start "chain" each leading node --> <xsl:apply-templates select="*[1] | *[sectpr]"/> </xsl:copy> </xsl:template> <xsl:template match="body/*[sectpr]" priority="1"> <mytag> <xsl:copy> <xsl:apply-templates/> </xsl:copy> <!-- call next sibling in chain --> <xsl:apply-templates select="following-sibling::*[1][not(sectpr)]"/> </mytag> </xsl:template> <xsl:template match="body/*"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> <!-- call next sibling in chain --> <xsl:apply-templates select="following-sibling::*[1][not(sectpr)]"/> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment