[Home] [By Thread] [By Date] [Recent Entries]
Hi,
I have this requirement from a client to retain all the entity references in their xml files after transformation so what i did was collect all the entities in the DTD and then created a character-map for single-character entities. For multi-character ones, i created a used a function to search and replace all occurrences in a text node. My problem is when i use the function and return the value, xslt escapes the ampersand symbol as & and i don't know how i can unescape it without unescaping the real ampersand character. Below is a snippet of my stylesheet and the output that i'm getting. XSL: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="f;data"> <xsl:character-map name="brillMaps"> <!-- character mapping for single-character entities--> </xsl:character-map> <!--variable that holds the values of the multi-character entities--> <xsl:variable name="entityTable" as="element()+"> <entity> <search>c̲h̲k̲</search> <replace>&chkeiubareiubareiubar;</replace> </entity> <!-- other multi-character entities--> </xsl:variable> <xsl:function name="f:replace-all"> <xsl:param name="input" as="xs:string"/> <xsl:param name="words-to-replace" as="xs:string*"/> <xsl:param name="replacement" as="xs:string*"/> <xsl:sequence select="if (exists($words-to-replace)) then f:replace-all(replace($input, $words-to-replace[1], $replacement[1]),remove($words-to-replace,1),remove($replacement,1)) else $input"/> </xsl:function> <xsl:output method="xml" encoding="UTF-8" use-character-maps="brillMaps"/> <xsl:template match="/"> <xsl:variable name="str" select="'& test test the quick brown fox textc̲h̲k̲text test test the quick brown fox'"/> <xsl:variable name="searchStr" as="xs:string*" select="$entityTable/search[matches($str,.)]"/> <test> <xsl:value-of select="f:replace-all($str,$entityTable/search[matches($str,.)],$entityTable/search[matches($str,.)]/following-sibling::replace)"/> <xsl:value-of select="$entityTable[1]/replace" disable-output-escaping="yes"/> </test> </xsl:template> </xsl:stylesheet> java net.sf.saxon.Transform CharMap.xsl CharMap.xsl > out.xml out.xml -- <test>& test test the quick brown fox text&chkeiubareiubareiubar;text test test the quick brown fox&chkeiubareiubareiubar;</test> -- *Jeff*
|

Cart



