XSLT - sneaky insertion(xsl:copy)

Immuhhemn

New Member
I will start with codes - we all like codes :DXML:\[code\] <report> <subject> <subjectId>1</subjectId> <name>John</name> <surname>Doe</surname> </subject> <subject> <subjectId>2</subjectId> <name>Frank</name> <surname>Timothy</surname> </subject> <individual> <individualId>10</individualId> <name>Isaac</name> <surname>Newton</surname> <co-worker> <subject> <subjectId>1</subjectId> <inXml>true</inXml> </subject> <subject> <subjectId>2</subjectId> <inXml>true</inXml> </subject> </co-worker> </individual> <owner> <subject> <subjectId>2</subjectId> <inXml>true</inXml> </subject> <share>100</share> </owner> <individual> <individualId>10</individualId> <inXml>true</inXml> </individual> </report>\[/code\]XSLT:\[code\] <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> <xsl:output method="xml" indent="yes" /> <xsl:template match="individual[inXml='true']"> <xsl:variable name="indId" select="./individualId/text()" /> <xsl:variable name="result" select="//individual[not(inXml) and individualId=$indId]/*" /> <xsl:choose> <xsl:when test="$result != ''"> <xsl:copy> <xsl:apply-templates select="$result" /> </xsl:copy> </xsl:when> <xsl:otherwise> <xsl:copy-of select="." /> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="subject[inXml='true']"> <xsl:variable name="subId" select="./subjectId/text()" /> <xsl:variable name="result" select="//subject[not(inXml) and subjectId=$subId]/*" /> <xsl:choose> <xsl:when test="$result != ''"> <xsl:copy> <xsl:apply-templates select="$result" /> </xsl:copy> </xsl:when> <xsl:otherwise> <xsl:copy-of select="." /> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()" /> </xsl:copy> </xsl:template> </xsl:stylesheet>\[/code\]What I am tryin to achieve? - I want to copy subject / individual in a place where "inXml" tag appears. XSLT seems to work..but for slightly bigger xmls.. around 1MB (it's not big..)my java application fails with java.lang.OutOfMemoryError: Java heap space.I redirected stream to file..and surprisingly - the file with result of transformation was growing with speed of light - after 15sec around 300mb! :D hehehe - which proves there must be some error in my xlst which results in infinite loop.What is important - while copying of nodes it may happen that there is already "inXml" inside - that's why i am applying template or result. XML that i prepared is depicting the problem.Thank you in advance!
 
Back
Top