tags:

views:

68

answers:

3

I have some code wrapped in a CDATA tag in an xslt file:

 <span>
   <xsl:text><![CDATA[<asp:LinkButton ID ="]]></xsl:text><xsl:value-of select="ID"/>
   <xsl:text><![CDATA[" onclick="LinkClicked">]]></xsl:text >

   <xsl:value-of select="."/>
   <xsl:text><![CDATA[</asp:LinkButton>]]></xsl:text>
 </span> 

When it renders in the page it is &gt; and &lt;, how do I get around this?

Now I know a work around as I can do a replace within the string after this is rendered, but this doesn't seem like the best approach.

+1  A: 

This doesn't answer your question, but there is another way to include .net tags.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:asp="remove">

Note the xmlns:asp="remove"

No need to wrap your control tag in xsl:text or in a cdata section.

ScottE
+2  A: 

Why are you wrapping a tag in a CDATA? The behavior you're describing is exactly what you'd expect, which is why people use CDATA for content, which they want to be escaped.

pdr
new to xslt and used cdata to get around the tag warnings, didn't realize how to call ID like tom suggested, although still get error namespace not defined
James Campbell
+4  A: 

You need to change your XSLT code:

<span>
  <asp:LinkButton ID="{ID}" onclick="LinkClicked">
    <xsl:value-of select="."/>
  </asp:LinkButton>
</span> 

All this CDATA juggling is not only bad for everybody's eyes, but also the wrong approach no matter how you look at it.

Declare the asp namespace in XSLT and use actual ASP.NET code, not text that looks like code.

Tomalak
Thank you very much
James Campbell
Oh yeah now I know why I used CDATA I am getting an error in the designer in Visual studio saying: namespace prefix 'asp' not defined
James Campbell
That's because you did not correctly define that prefix. Like I said "Declare the asp namespace in XSLT".
Tomalak
Thanks again, decleared the namespace works like a charm, you rock tom!
James Campbell
Sources are not 100% consistent, but Microsoft seem to use `xmlns:asp="http://schemas.microsoft.com/ASPNET/20"` as the asp namespace declaration in XSLT.
Tomalak
Hey Tom, can you please take a look at my edit as I am having issues with that ID, and really don't see opening yet another question, thanks
James Campbell
@Vecdid: You really should have opened another question. This thread is now two questions that are completely unrelated as far as their nature is concerned. They only happen to be in the same source code, which means nothing. That being said, you must use `<asp:LinkButton ID ="{../ID}" onclick="LinkClicked">`. Please do not expand this question further, I'd even say you restore it to its previous state and open a new one. Furthermore, please start to indent your XSLT code, it looks really messy and hard to understand.
Tomalak
I did open another question, sorry and edited by the time you replied
James Campbell
Here is the other question:http://stackoverflow.com/questions/2281447/need-help-with-xslt
James Campbell
Oh yeah and your solution worked perfectly, and I think I get it now, thank you again you have been a huge help, once you post the answer in the other question I will accept it.
James Campbell
@Vecdid: Been there, done that.
Tomalak