Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: C# and xsl problem


Message #1 by "Daniel Fisher" <lennybacon@y...> on Tue, 13 Nov 2001 15:04:43 +0100
Hello List

I got this xsl working with asp. Now i try to use it in aspx
But i don=B4t get access to the cdata-section. Whats wrong?


Xsl-file:
<xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/TR/WD-xsl">
        <xsl:template match=3D"/">
        <link rel=3D"stylesheet" href=3D"../lib/articles.css"
type=3D"text/css"/>
        <font class=3D"articletitle">
        <xsl:value-of select=3D"article/title"/>
        </font>
        <br/>
        <font class=3D"articleauthor">
        <a>
        <xsl:attribute name=3D"href">
        mailto:<xsl:value-of select=3D"article/email"/>
        </xsl:attribute>
        <xsl:value-of select=3D"article/author"/>
        </a>
        </font>
        <br/>
        <br/>
                <xsl:apply-templates select=3D"*"/>
        </xsl:template>
        <xsl:template match=3D"*|cdata()">
                <font class=3D"articletext">
                <xsl:copy><xsl:apply-templates
select=3D"*|cdata()"/></xsl:copy>
                </font>
        </xsl:template>
</xsl:stylesheet>

Xml-file:
<article>
   <author>Daniel</author>
   <email></email>
   <categories>news</categories>
   <timestamp>10/18/2001 4:42:35 PM</timestamp>
   <title>test</title>
   <content>
     <![CDATA[
     Das ist ein Teaser mit <b>html</b>...
     ]]>
   </content>
   <startdate>18.10.2001</startdate>
   <enddate>01.11.2001</enddate>
</article>


Aspx-file
<%@ Page Language=3D"C#" Debug=3D"true" %>
<%@ Import Namespace=3D"System" %>
<%@ Import Namespace=3D"System.IO" %>
<%@ Import Namespace=3D"System.Web" %>
<%@ Import Namespace=3D"System.Xml" %>
<%@ Import Namespace=3D"System.Xml.XPath" %>
<%@ Import Namespace=3D"System.Xml.Xsl" %>

<script language=3D"C#" runat=3D"server">

protected void Page_Load(Object Src, EventArgs E)
{
    XslTransform xslt =3D new XslTransform();
    xslt.Load(Server.MapPath("database/article.xsl"));

    XPathDocument doc =3D new
XPathDocument(Server.MapPath("database/1.xml"));

    XmlTextWriter writer =3D new XmlTextWriter("trans.xml", null);

    xslt.Transform(doc, null, writer);
    writer.Close();

    StreamReader stream =3D new StreamReader("trans.xml");
    Response.Write(stream.ReadToEnd());
}
</script>




_________________________________________________________

Do You Yahoo!?

Get your free @yahoo.com address at http://mail.yahoo.com




  Return to Index