1
votes

I had some classes I was serializing out using XMLSerializer, then transforming using XSLT into various formatted emails or web service calls. All was well.

We started using Linq in some parts of the data layer, and I needed to serialize out some of the Linq objects to be consumed by the XSL Stylesheets. I decided it was probably best to move towards using the DataContractSerializer instead of XMLSerializer.

I got the DataContracts and everything set up, and things serialize out nicely with a couple minor changes to the entity names... BUT now the stylesheets won't process the XML at all. I really have no idea why I'm not getting at least something... basically all that comes out is the data stripped of the xsl tags though.

Any ideas what would cause that?

EDIT:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="CallTicket">

Here is the XML generated from DataContractSerializer before I modified the DataContract declaration:

<CallTicket xmlns="http://schemas.datacontract.org/2004/07/CRMInterface.CRMData" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
3

3 Answers

3
votes

You most likely have a namespace issue. For example:

If the XML looks like this

<Root xmls="http://www.example.org/1" ....

<test>one</test>

Then you'll have to do one of two things in the XSLT

Specifically reference the namespace and use the prefix accordingly

<xsl:stylesheet xmlns:ex="http://www.example.org/1" ....>`
   ...

    <myTag><xsl:select value-of="//ex:test"/></myTag>`

or

If there is only one namespace make it the default namespace of the XSLT file:

<xsl:stylesheet xmlns="http://www.example.com/1" ...`

...
   <myTag><xsl:select value-of="//test"/></myTag>`
2
votes

Could it be that your new XML has XML namespaces in it, that your XSLT dosen't deal with properly?

Can you show us relevant parts of your XML and XSLT files?

Marc

0
votes

I think I figured it out, the namespaces are more important than I realized. It works if I set DataContractAttribute(Namespace="") for each class being serialized. I have some more work to do with the linq entities... but on the right track.

The only thing that gets me is that there was no reference to the namespace in the xslt file...