[Mono-list] XSLT Problems

Ivan Hawkes blackhawk@ivanhawkes.com
Fri, 4 Jul 2003 21:15:45 +0100


--Boundary-00=_xBeB/DEGjx6tqTm
Content-Type: Text/Plain;
  charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Description: clearsigned data
Content-Disposition: inline

=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ok, I've Googled until my eyes bugged out of my head but no answer to this=
=20
one...

I have some XML and an XSL file to transform that into some HTML output. De=
ep=20
within the program I am converting is a call to transform the XML using the=
=20
XSL file provided. If I perform the transform from the command line with=20
xsltproc then it all works, but the code using C# fails. Output is below:

[ivan@hal9000 simpletest]$ mono simpletest.exe
=EF=BB=BFStarting up
Path=3D/home/ivan/simpletest/Stylesheets
Entity: line 1: warning: Namespace prefix xsl is not defined
<?xml version=3D"1.0" encoding=3D"utf-8"?><xsl:stylesheet=20
version=3D"1.0"><xsl:import
                                                                  ^
Entity: line 1: warning: Namespace prefix xsl is not defined
encoding=3D"utf-8"?><xsl:stylesheet version=3D"1.0"><xsl:import=20
href=3D"DeepCopy.xsl"
                                                                           =
  =20
^
Entity: line 1: warning: Namespace prefix xsl is not defined
opy.xsl" /><xsl:output method=3D"xml" version=3D"1.0" encoding=3D"UTF-8"=20
indent=3D"yes"
                                                                           =
  =20
^
Entity: line 1: warning: Namespace prefix xsl is not defined
xml" version=3D"1.0" encoding=3D"UTF-8" indent=3D"yes" /><xsl:template=20
match=3D"content
                                                                           =
  =20
^
Entity: line 1: warning: Namespace prefix xsl is not defined
:value-of select=3D"normalize-space=20
(//placeholder[@id=3D'1']/placeholder-content)"
                                                                           =
  =20
^
Entity: line 1: warning: Namespace prefix xsl is not defined
:value-of select=3D"normalize-space=20
(//placeholder[@id=3D'2']/placeholder-content)"
                                                                           =
  =20
^
compilation error: element stylesheet
xsltParseStylesheetProcess : document is not a stylesheet
=20
Unhandled Exception: System.Xml.XmlException: Error creating stylesheet
in <0x000d9> 00 System.Xml.Xsl.XslTransform:GetStylesheetFromString (string)
in <0x0006f> 00 System.Xml.Xsl.XslTransform:Load=20
(System.Xml.XPath.XPathNavigator)
in <0x00031> 00 System.Xml.Xsl.XslTransform:Load=20
(System.Xml.XPath.IXPathNavigable)
in <0x00044> 00 Interesource.Util.Xslt.XsltHelper:Transform=20
(System.Xml.XPath.IXPathNavigable,System.Xml.XPath.IXPathNavigable,System.I=
O.TextWriter,System.Xml.Xsl.XsltArgumentList)
in <0x0003e> 00 Interesource.Util.Xslt.XsltHelper:Transform=20
(System.Xml.XPath.IXPathNavigable,System.Xml.XmlReader,System.IO.TextWriter=
,System.Xml.Xsl.XsltArgumentList)
in <0x0008c> 00 Interesource.Publish.Client.ContentElement:Transform=20
(System.IO.TextWriter,System.Xml.Xsl.XsltArgumentList,System.Xml.XPath.IXPa=
thNavigable)
in <0x0006d> 00 Interesource.Publish.Client.ContentElement:Transform=20
(System.IO.TextWriter,System.Xml.Xsl.XsltArgumentList)
in <0x00067> 00 Interesource.Publish.Client.ContentElement:Transform=20
(System.Xml.Xsl.XsltArgumentList)
in <0x00022> 00 Interesource.Publish.Client.ContentElement:Transform ()
in <0x000d9> 00 simpletest.SimpleTest:Main (string[])
=20
The transform routine looks like the following:

		/// <summary>
		/// Transforms the instance doucment using the provided stylesheet.
		/// </summary>
		/// <param name=3D"stylesheet">The stylesheet to use.</param>
		/// <param name=3D"instanceDoc">An <see cref=3D"IXPathNavigable"/> over t=
he XML=20
data to transform.</param>
		/// <param name=3D"output">The output stream to write to.</param>
		public static void Transform(IXPathNavigable stylesheet, IXPathNavigable=
=20
instanceDoc, TextWriter output, XsltArgumentList args)
		{
			XslTransform x =3D new XslTransform();
			x.Load(stylesheet);

			XmlTextWriter writer =3D new XmlTextWriter(output);
			writer.Formatting =3D Formatting.None;

			x.Transform(instanceDoc, args, writer);
		}

Now, for some reason, the Load function isn't happy with the XSL file, even=
=20
though from the output provided you can see that it has loaded the correct=
=20
file.

Any clues?

My Setup:
	OS RedHat 9.0 (Shrike - stock)
	Mono/MCS built from CVS today
=09
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iQIVAwUBPwXgcfr1e7bH1pzBAQJ6thAAjXLA47kmelf96fA3c2tQKrdatyfV36YS
lS6Y6DOQZSeYowkopUp3twPPDhl7XsP1SHfan6xllD41hRKlQCUQYPYY1lJ+XqTw
VWQKl1DQetxd+qcAzo6CSA4P7eq7lEtq1DJ/Uj5+cyjkwmS8qPM7AkA2YovHitxO
II2UPE+n2ZIttSCkFMU+RudXzZeQ5jTYh1ekD25KVOW5M4l6fTVgsLQQzmtvX2DB
QvDU4FVpI+Fjdn4f4S2437tEq0oKVYstxah8LflMe8fPtz0TYInv00eZvutFYzGl
xhAODbDZobISBhtTwjer2ea0If0VBEHutb5WlEANYZGyDLYPHE0ajqQtcAid06+O
3zmn5FURCuOlXzFxJ2ABA90PFAciUpMD3vUO/pvohIpWsxf4jranm0eTIHahncs2
0XffszRXPd0HHkynwlSOxmMvn0AapOpTYO7GjqKPzzL1bsIH86q6mhM4hfocUvS8
4dB3wmgijre8fLo9aiQbgPZvua8zsUZU8D3D9pR/KwVqq5IsHJJeBqApOGsfOcmZ
VIuiz0rVfkUtYgNeVVbbArtojkOi5ziwMs0+la+IyHQ9Ut+YLM0pM0PjJVSBYdky
HD1f9AuyxATmx0xARrxNsq1pOgGFW3bwm4TBfNoY9qGikGMG3NylW5yYfP7YGrS4
r+FASb9Fgv8=3D
=3DQ0EE
=2D----END PGP SIGNATURE-----

--Boundary-00=_xBeB/DEGjx6tqTm
Content-Type: text/xml;
  charset="iso-8859-1";
  name="DeepCopy.xsl"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="DeepCopy.xsl"

<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<xsl:stylesheet version=3D"1.0" xmlns:xsl=3D"http://www.w3.org/1999/XSL/Tra=
nsform">

	<!-- default copy everything template -->
	<xsl:template match=3D"*" mode=3D"content">
		<xsl:element name=3D"{name()}">
			<!-- copy all of the attributes -->
			<xsl:for-each select=3D"@*">
				<xsl:attribute name=3D"{name()}"><xsl:value-of select=3D"."/></xsl:attr=
ibute>
			</xsl:for-each>

			<xsl:apply-templates mode=3D"content"/>
		</xsl:element>
	</xsl:template>

	<xsl:template match=3D"BR" mode=3D"content">
		<br />
	</xsl:template>
=09
	<xsl:template match=3D"TD" mode=3D"content">
		<td>
			<!-- copy all of the attributes -->
			<xsl:for-each select=3D"@*">
				<xsl:attribute name=3D"{name()}"><xsl:value-of select=3D"."/></xsl:attr=
ibute>
			</xsl:for-each>
			<xsl:attribute name=3D"class">t70</xsl:attribute>
			<xsl:apply-templates mode=3D"content"/>
		</td>
	</xsl:template>


	<xsl:template name=3D"make-upper">
		<xsl:param name=3D"upper-text"/>
		<xsl:value-of select=3D"translate($upper-text, 'abcdefghijklmnopqrstuvwxy=
z=C3=A9=C3=A8', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ=C3=89=C3=88')"/>
	</xsl:template>

</xsl:stylesheet>
--Boundary-00=_xBeB/DEGjx6tqTm
Content-Type: text/xml;
  charset="iso-8859-1";
  name="notes.xsl"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="notes.xsl"

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="DeepCopy.xsl"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
		
	<xsl:template match="content">
		<p class="newsTitle"><xsl:value-of select="normalize-space (//placeholder[@id='1']/placeholder-content)"/>
		<br/><span class="p"><xsl:value-of select="normalize-space (//placeholder[@id='2']/placeholder-content)"/></span></p>
	</xsl:template>	
		
</xsl:stylesheet>

--Boundary-00=_xBeB/DEGjx6tqTm
Content-Type: text/xml;
  charset="iso-8859-1";
  name="test.xml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="test.xml"

<ir-content-item id="10" name="Test" template="notes.xml"><content-metadata><standard-metadata><authors><author id="1" first-name="Ivan" last-name="Hawkes" email-address="blackhawk@ivanhawkes.com"></author></authors><modified date="Thu Jul
3 22:24:46 UTC+0100 2003"></modified></standard-metadata></content-metadata><content><placeholder id="1"><placeholder-content>Some Notes</placeholder-content></placeholder><placeholder id="2"><placeholder-content>I made some notes about it
for the sidebar. I made some notes about it for the sidebar. I made some notes about it for the sidebar. I made some notes about it for the sidebar. I made some notes about it for the sidebar.</placeholder-content></placeholder></content></ir-content-item>
--Boundary-00=_xBeB/DEGjx6tqTm--