Avatar of PFPCDUBIT
PFPCDUBIT

asked on 

Cant get XSLT to transform C# XMLCompiledTransform

Ive got an XML file i want to transform using XSLT.  I have an xslt file i have created that will work fine with the Server.CreateObject("Microsoft.XMLDOM") in simple asp.  I cannot get the same xslt to work using XMLCompiledTransform in c#.  Im using .net 3.5.

The only output i get is the html outside of the templates.
This is the XSLT
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:bb=" http://services.bloomberg.com/datalicense/dlws/ps/20071001" >
 
<xsl:output method="html"/>
 
<xsl:template match="SubmitGetDataRequest">
	<html>
		<head>
			<link rel="Stylesheet" href="/style/pnc.css" type="text/css"/>
		</head>
		<body>
			
			<h1>Request Files</h1>
			<xsl:apply-templates/>
 
	</body>
</html>
</xsl:template>
 
<xsl:template match="bb:headers">
	<h2>Headers:</h2>
	<table border="1" cellpadding="2" cellspacing="2">
	<xsl:for-each select ="*">
   <tr>
   <td><b><xsl:value-of select="name(.)"/></b></td>
   <td><xsl:apply-templates/></td>
   </tr>
	</xsl:for-each>
	</table>
</xsl:template>
 
<xsl:template match="bb:fields">
	<h2>Fields:</h2>
	<table border="1" cellpadding="2" cellspacing="2">
	<xsl:for-each select ="*">
   <tr>
   <td><b><xsl:value-of select="name(.)"/></b></td>
   <td><xsl:apply-templates/></td>
   </tr>
	</xsl:for-each>
	</table>
</xsl:template>
 
<xsl:template match="bb:instruments">
	<h2>Instruments:</h2>
	<table border="1" cellpadding="2" cellspacing="2">
		<xsl:for-each select ="bb:instrument">
	   <tr>
	   <td><b><xsl:value-of select="name(.)"/></b><br/>
	   </td><td>
		   <xsl:apply-templates/>
		   <table border="1" cellpadding="2" cellspacing="2" width="100%">
				<xsl:for-each select ="*">
					<tr><td><b><xsl:value-of select="name(.)"/></b></td>
					<td><xsl:apply-templates/></td></tr>
				</xsl:for-each>
				</table>
			</td>
			</tr>
		</xsl:for-each>
	</table>
</xsl:template>
 
<xsl:template match="*"/>
 
</xsl:stylesheet>
 
This is the sample XML file i want to transform
 
 
<?xml version="1.0" encoding="utf-8"?>
<SubmitGetDataRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <headers xmlns="http://services.bloomberg.com/datalicense/dlws/ps/20071001">
    <closingvalues>true</closingvalues>
    <derived>true</derived>
    <secmaster>true</secmaster>
  </headers>
  <fields xmlns="http://services.bloomberg.com/datalicense/dlws/ps/20071001">
    <field>CRNCY</field>
    <field> MHIS_CLOSE_ON_PX:20090223:P</field>
    <field> MHIS_CLOSE_ON_PX:20090223:P</field>
    <field> PRICING_SOURCE</field>
  </fields>
  <instruments xmlns="http://services.bloomberg.com/datalicense/dlws/ps/20071001">
    <instrument>
      <id>US4592001014</id>
      <type>ISIN</type>
    </instrument>
    <instrument>
      <id>5698790</id>
      <type>SEDOL</type>
    </instrument>
  </instruments>
</SubmitGetDataRequest>
 
This is the c# code:
 
string s_xsltString = System.IO.File.ReadAllText( Server.MapPath("xml/request.xslt") );
string s_xmlString = System.IO.File.ReadAllText( Server.MapPath("xml/request.xml") );
XmlTextReader xsltReader = new XmlTextReader(s_xsltString);
XmlTextReader xmlReader = new XmlTextReader(s_xmlString);
XmlTextWriter transformedXml = new XmlTextWriter(stringWriter);
XslCompiledTransform xsltTransform = new XslCompiledTransform();
xsltTransform.Load(xsltReader);
xsltTransform.Transform(xmlReader, transformedXml);

Open in new window

Web Languages and StandardsC#

Avatar of undefined
Last Comment
PFPCDUBIT

8/22/2022 - Mon