| re: Xslt transform in code yields nothing
Since I don't have access to your BuildTableXml() method and other custom
stuff, I simply took your XML and XSLT into 2 separate files applied
XslTransform over it and it does produce the expected output (C# code)
Can you debug your application and see if you are BuildTableXml is returning
good Xml ?
Thanks
Pranav
"Andy" <ajohnstone@capcitypress.com> wrote in message
news:1129664333.559528.100070@g43g2000cwa.googlegr oups.com...[color=blue]
> Hi all,
>
> I'm having a problem doing an Xslt transform in code. I've done it
> before, so I'm not really sure why its not working. The problem is
> that the result of the transform is an empty string. I expected the
> xml to be transformed into a plain text document. Everything works
> fine when i transform using XmlPad. Here's the code (which does
> generate the Xml properly):
>
> Sample XML:
> <?xml version="1.0" encoding="utf-8" ?>
> <dalGen>
> <table name="test" className="Test" provider="SqlServer">
> <columns>
> <column name="Id" propertyName="Id" dataType="int" isKeyPart="true"
> isReadOnly="false" />
> <column name="FirstName" propertyName="FirstName" dataType="string"
> isKeyPart="false" isReadOnly="false" />
> <column name="LastName" propertyName="LastName" dataType="string"
> isKeyPart="false" isReadOnly="false" />
> <column name="Ssn" propertyName="Ssn" dataType="string"
> isKeyPart="false" isReadOnly="false" />
> </columns>
> </table>
> </dalGen>
>
> The XSLT:
> <?xml version="1.0" encoding="UTF-8" ?>
>
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:output method="text" media-type="text/plain"
> omit-xml-declaration="yes" />
>
> <xsl:template match="dalGen">
> using System;
>
> using Ccp.Core.Data;
> using Ccp.Core.Data.Providers;
>
> namespace Ccp.Core.Data.Entities {
> <xsl:apply-templates />
> }
> </xsl:template>
>
> <xsl:template match="table">
>
> public class <xsl:value-of select="./@className" /> : <xsl:value-of
> select="./@provider" />Entity {
> <xsl:apply-templates mode="fields" select="columns" />
> <xsl:apply-templates mode="properties" select="columns" />
> }
>
> </xsl:template>
>
> <xsl:template match="columns" name="DataFields" mode="fields">
> #region DataFields
> <xsl:apply-templates select="column" mode="fields" />
> #endregion
> </xsl:template>
>
> <xsl:template match="column" name="DataField" mode="fields">
> /// <summary>Stores the value of the field <c><xsl:value-of
> select="./@name" /></c>.</summary>
> protected <xsl:value-of select="./@dataType" /> _<xsl:value-of
> select="./@propertyName" />;
> </xsl:template>
>
> <xsl:template match="columns" name="Properties" mode="properties">
> #region Properties
> <xsl:apply-templates select="column" mode="properties" />
> #endregion
> </xsl:template>
>
> <xsl:template match="column" name="Property" mode="properties">
> /// <summary>Gets or sets the <c><xsl:value-of select="./@name"
> /></c>.</summary>
> [Persisted( <xsl:value-of select="./@isKeyPart" />, "<xsl:value-of
> select="./@name" />", <xsl:value-of select="./@isReadOnly" /> )]
> public <xsl:value-of select="./@dataType" /><xsl:text>
> </xsl:text><xsl:value-of select="./@name" /> {
> get { return _<xsl:value-of select="./@propertyName" />; }
> set { _<xsl:value-of select="./@propertyName" /> = value; }
> }
> </xsl:template>
> </xsl:stylesheet>
>
>
> The C# code:
> public override string GenerateDALClass( string tableName ) {
> XslTransform xsl;
> XmlTextReader reader;
> MemoryStream output;
> StreamReader outReader;
> XmlDocument xml;
> string result;
>
> reader = new XmlTextReader(
> Assembly.GetExecutingAssembly().GetManifestResourc eStream(
> GetType(),
> "DalClass.xslt"
> )
> );
>
> xsl = new XslTransform();
> xsl.Load( reader, null, GetType().Assembly.Evidence );
>
> xml = BuildTableXml( tableName );
>
> using( output = new MemoryStream() ) {
> xsl.Transform(
> xml.CreateNavigator(),
> null,
> output,
> null
> );
>
> using( outReader = new StreamReader( output ) ) {
> result = outReader.ReadToEnd();
> }
> }
>
> return result;
> }
>
>
>
> Thanks for any help.
> Andy
>[/color] |