xsl-list
[Top] [All Lists]

Re: [xsl] Problem with ampersands

2006-09-26 19:06:55
andrew welch wrote:
If you really must deliver XML with the entities in place I would
suggest using a placeholder element (eg <entityA/>) to represent it in
the output and the post process the result with a suitable language to
replace the placeholder elements with the entity references.
This would probably the best way to go with this problem. However how do i go about replacing all the occurrences of the entity equivalent with an element? Is this method the right approach?

<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="'&#x0386; &amp; test test the quick brown fox text&#x0063;&#x0332;&#x0068;&#x0332;&#x006B;&#x0332;text test test the quick brown fox'"/> <xsl:variable name="replacementStr" as="xs:string*" select="$entityTable/search[matches($str,.)]/following-sibling::replace/concat('&#x3c;entity name=&#x22;',.,'&#x22;/&#x3e;')"/>
   <test>
<xsl:value-of select="f:replace-all($str,$entityTable/search[matches($str,.)],$replacementStr)"/>
   </test>
</xsl:template>

Wherein, i have a character map with this values:

<xsl:output-character string="&#x3c;" character="&#x3c;"/>
<xsl:output-character string="&#x3e;" character="&#x3e;"/>

Thanks,
-- Jeff



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>