[xsl] Copying all comments [xsltproc 1.0]

Subject: [xsl] Copying all comments [xsltproc 1.0]
From: pankaj.c@xxxxxxxxxxxxxxxxxx
Date: Mon, 4 Oct 2010 17:05:03 +0530
Input:
====
<!--<query id="Q26">ED: &#x00C8; stata cambiata valutazione in 
accertamento perch&eacute; in altri capitoli viene citato 
l&rsquo;accertamento come prima fase del processo di assistenza 
infermiersitica. Ok?</query>-->

Output
====
&lt;query id="Q26"&gt;ED: &amp;#x00C8; stata cambiata valutazione in 
accertamento perch&amp;#x00E9; in altri capitoli viene citato 
l&amp;#x2019;accertamento come prima fase del processo di assistenza 
infermiersitica. Ok?&lt;/query&gt;

Desired output:
========
<query id="Q26">ED: &#x00C8; stata cambiata valutazione in accertamento 
perch&eacute; in altri capitoli viene citato l&rsquo;accertamento come 
prima fase del processo di assistenza infermiersitica. Ok?</query>


Tried XSLT:
=======
    <xsl:for-each select="//comment()">
     <xsl:choose>
            <xsl:when test="substring(.,2,8)='query id'">
                    <xsl:text>&#x0000A;</xsl:text>
                     <xsl:value-of select="."/>
            </xsl:when>
   </xsl:choose>
  </xsl:for-each>


I even tried different manipulation (substring(), substring-after() etc)to 
get this done, for instance below one.

    <xsl:for-each select="//comment()">
        <xsl:choose>
            <xsl:when test="substring(.,2,8)='query id'">
            <xsl:text>&#x0000A;</xsl:text>
               <xsl:element name="query">
                   <xsl:value-of select="."/>
                </xsl:element>
                <xsl:value-of select="."/>
        </xsl:when>
        </xsl:choose>
    </xsl:for-each>

Just to add, notice &#x00C8; changing to  &amp;#x00C8; and similarly &gt; 
&lt; (thats what xsl:value-of does. :-( ). Would have been much easier 
with 2.0 with the use of 
<xsl:sequence 
select="replace(codepoints-to-string(string-to-codepoints($arg)), 
'\[#x([0-9A-Za-z]+)\]', '&#xE000;#x$1;')"/> and replace() function.
and so on,
but alas I am using 1.0. Is there a way to get this done in 1.0?

Thanks for hints.

Pankaj 

Current Thread