KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
UPDATE: I added an answer to this question which incorporates almost all the suggestions which have been given. The original template given in the code below needed 45605ms to finish a real world input document (english text about script programming). The revised template in the community wiki answer brought the runtime down to 605ms ! I'm using the following XSLT template for replacing a few special characters in a string with their escaped variants; it calls itself recursively using a divide-and-conquer strategy, eventually looking at every single character in a given string. It then decides whether the character should be printed as it is, or whether any form of escaping is necessary: <xsl:template name="escape-text"> <xsl:param name="s" select="."/> <xsl:param name="len" select="string-length($s)"/> <xsl:choose> <xsl:when test="$len >= 2"> <xsl:variable name="halflen" select="round($len div 2)"/> <xsl:variable name="left"> <xsl:call-template name="escape-text"> <xsl:with-param name="s" select="substring($s, 1, $halflen)"/> <xsl:with-param name="len" select="$halflen"/> </xsl:call-template> </xsl:variable> <xsl:variable name="right"> <xsl:call-template name="escape-text"> <xsl:with-param name="s" select="substring($s, $halflen + 1)"/> <xsl:with-param name="len" select="$halflen"/> </xsl:call-template> </xsl:variable> <xsl:value-of select="con
Tags (comma-separated)
Save Edits
Cancel