views:

1187

answers:

3

I have an xml in which i have stored some html under comments like this

 <root> 
   <node>
     <!-- 
            <a href="mailto:[email protected]"> Mail me </a>
      -->
</node>
</root>

now in my Transform Xslt code of mine i am giving XPathNavigator which is pointing to node and in xslt i am passing the comment value of as a parameter.

assuming $href to be <a href="mailto:[email protected]"> Mail me </a>

in xslt i am doing <xsl:value-of select="$href" disable-output-escaping="yes">

but $href is still escaped the result of xslt transformation comes up with < >

Does any one know whats wrong with it any help in this regard would be highly appericiated.

Thanks Regards Azeem

+2  A: 

When part of the comment the node looses its special meaning - thus "href" is not a node so you cannot use it to select stuff.

You can select comments like this:

<xsl:template match="/">
<xsl:value-of select="/root/node/comment()" disable-output-escaping="yes"/>
</xsl:template>

This will produce based on your XML input:

cristi:tmp diciu$ xsltproc test.xsl test.xml 
<?xml version="1.0"?>

        <a href="mailto:[email protected]"> Mail me </a>
diciu
A: 

i did tried what u just said didn't worked the xml i am using is

<?xml version="1.0" ?>
  <root>
    <institution id="1">
     <data>
     <ahrefmail>
      <!--
        <a href='mailto:[email protected]' class='text'></a>
             -->
     </ahrefmail>

     <mail>
      [email protected]
     </mail>
     </data>
    </institution>


    <institution id="2">
     <data>
     <ahrefmail>
      <!--
        <a href='mailto:[email protected]' class='text'></a>
        -->
     </ahrefmail>

     <mail>
      [email protected]
     </mail>
     </data>
    </institution>

</root>

in xslt i am doing

where $id is passed as parameter == 1 the ahrefmail node is still escaped with lt & gt

Thanks Regards Azeem

azimyasin
The XSLT code is missing...
bortzmeyer
+1  A: 

As diciu mentioned, once commented the text inside is no longer XML-parsed.

One solution to this problem is to use a two-pass approach. One pass to take out the commented <a href=""></a> node and place it into normal XML, and a second pass to enrich the data with your desired output: <a href="">Your Text Here</a>.

A second, single-pass approach would be to extract the text you need from the comment (in this case the email address) via a regular expression (or in our case just pulling from the XML), and then create the markup needed around it.

<xsl:template match="ahrefmail/comment()">
    <xsl:element name="a">
        <xsl:attribute name="href" select="../../mail"/>
        <xsl:attribute name="class" select="'text'"/>
        <xsl:text>Mail Me!</xsl:text>
    </xsl:element>
</xsl:template>

This assumes you already have an identity template in place

Jweede