471,318 Members | 3,268 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

Using XLS Template In C#

Hello,

I'm using Visual Studio.NET 2003 and I'm wondering that
is it possible to call XSL file's template to transform a XML file?

I have following files.

A XML file below
<?xml version="1.0" encoding="UTF-8"?>
<MODEL>
<Charge id="1">ABC</Charge>
<Charge id="2">DEF</Charge>
</MODEL>

and XLS file below containing two XSL templates, TempalteA and TemplateB

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- This is template "block" 1 -->
<xsl:template match='TemplateA'>
<table border="1">
<xsl:for-each select="Charge">
<tr>
<td><xsl:value-of select="@id"/></td>
<td><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<!-- This is template "block" 2 -->
<xsl:template match='TemplateB'>
<table border="1">
<xsl:for-each select="Charge">
<tr bgcolor="#0000FF">
<td><xsl:value-of select="@id"/></td>
<td><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

So, it it possible in C# to ask certain XML/XSL classes to transform
XML file above using e.g. XSL file's TemplateB?

I have had tried classes like XPathDocument, XslTransform and
XPathNavigator
but haven't succeeded. Can anyone please help?

Cheer,
Feb 5 '06 #1
3 4160
Grep,

You definitely should be using the XslTransform class. What is
happening when you use that?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Grep J" <gj*********@hotmail.com> wrote in message
news:ds**********@nyytiset.pp.htv.fi...
Hello,

I'm using Visual Studio.NET 2003 and I'm wondering that
is it possible to call XSL file's template to transform a XML file?

I have following files.

A XML file below
<?xml version="1.0" encoding="UTF-8"?>
<MODEL>
<Charge id="1">ABC</Charge>
<Charge id="2">DEF</Charge>
</MODEL>

and XLS file below containing two XSL templates, TempalteA and TemplateB

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- This is template "block" 1 -->
<xsl:template match='TemplateA'>
<table border="1">
<xsl:for-each select="Charge">
<tr>
<td><xsl:value-of select="@id"/></td>
<td><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<!-- This is template "block" 2 -->
<xsl:template match='TemplateB'>
<table border="1">
<xsl:for-each select="Charge">
<tr bgcolor="#0000FF">
<td><xsl:value-of select="@id"/></td>
<td><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

So, it it possible in C# to ask certain XML/XSL classes to transform
XML file above using e.g. XSL file's TemplateB?

I have had tried classes like XPathDocument, XslTransform and
XPathNavigator
but haven't succeeded. Can anyone please help?

Cheer,

Feb 5 '06 #2


Grep J wrote:

I'm using Visual Studio.NET 2003 and I'm wondering that
is it possible to call XSL file's template to transform a XML file?
Yes, using XslTransform.
I have following files.

A XML file below
<?xml version="1.0" encoding="UTF-8"?>
<MODEL>
<Charge id="1">ABC</Charge>
<Charge id="2">DEF</Charge>
</MODEL>

and XLS file below containing two XSL templates, TempalteA and TemplateB

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- This is template "block" 1 -->
<xsl:template match='TemplateA'>
That template will be applied to elements with the element name
TemplateA but your XML above has elements named MODEL and Charge so that
template will not be used at all when you run the stylesheet against the
XML.

<xsl:template match='TemplateB'>


Same for that template, it will be applied to elements with name
TemplateB but your XML document does not have any.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 5 '06 #3
For completeness only (I realise OP stated 2003/1.1) - but in 2005/2.0 this
is now replaced by XslCompiledTransform;

In a surprisingly helpful move MS even provide a migration page for moving
code between the two:
http://msdn2.microsoft.com/en-us/library/66f54faw.aspx

Marc
Feb 6 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sam | last post: by
4 posts views Thread by Pat Turner | last post: by
2 posts views Thread by Sylvia | last post: by
4 posts views Thread by Alexis | last post: by
3 posts views Thread by 胡岳偉(Yueh-Wei Hu) | last post: by
reply views Thread by Yueh-Wei Hu | last post: by
8 posts views Thread by Douglas | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.