[Home] [By Thread] [By Date] [Recent Entries]
Hi Pankaj,
see my comments below: Pankaj Chaturvedi wrote: Hi all, first thought: consider using XSLT 2.0, which has search and replace built in using the replace() function which can handle regular expression style search and replace in one call. Basically trying to convert [#x02010] (and other Unicode values) to their Second thought consider using XSLT 2.0: getting the numeric value of a character can be done using string-to-codepoints, which is not available in XSLT 1.0. Second thought (b): sorry, I see that you mean the literal string '[#...]'.... Below is what I am trying to do: Not doing something because your tool limits you is very dangerous... However, in this case, XMLSpy is correct. The underlying technology (XML) does not allow a literal &, simply because XSLT *is* XML and XML does not allow it. However, if you output as text, the serializer will output '&' when you put & somewhere. Third thought: use XSLT 2.0. It has the ability to add character maps. In a character map you can say that some character, say '$' (but using something from the Private Area Unicode ranges is recommended) can be mapped to some string. Using character maps you can get a literal '&' in the output. 2. I also need to replace "]" to ";" for which I was trying to call the another template with in <xml:template match="text()"> as below but doesn't seems to be working. XSLT is a functional language. You will have to call the replace function recursively. I believe there's an example on the exslt.org site which shows how you can do this for a multiple search and replace in a generic way. Fourth thought: use XSLT 2.0. All you'll end up with then is a nested replace(replace(....)) call. Fifth thought: use XSLT 2.0 for the whole shebang. Your whole solution will look like this: <xsl:output use-character-maps="searchreplace" /> <xsl:character-map name="searchreplace"> <xsl:output-character character="" string="&" /> </xsl:character> <xsl:template match="text()"> <xsl:sequence select="replace(., '\[#(\d+)\]', '#x\1;')" /> </xsl:template> Sixth thought: use XSLT 2.0. You seem to be using XMLSpy, which can handle XSLT 2.0. However, its engine is a bit flaky. If you run into problems, consider using either Gestalt XSLT 2.0 or Saxon XSLT 2.0 processors. Note: you may think that putting & inside the string-attribute of xsl:output-character creates & in the output, but this is not true. Since XSLT is XML, you must put & there. But to get the translation to serialize to literal & instead means double escaping: "&amp;" (but that is not what you are after here). Understanding the implications of using character references in XML is vital of headache-free working with XML and XSLT (plus all other XML related technologies in fact), but it can be hard at times to get it right in your head. Hope this helps, Cheers, -- Abel Braaksma
|

Cart



