473,221 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 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 4244
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sam | last post by:
I would like to store html templates in a database. By using perl I would like to retrive the template ask the user to fill the template and store the whole file is template + the user data in a...
2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
4
by: Pat Turner | last post by:
Hi, I have some XML like this: <family> <person name="bob"> <father ref="../../person" /> </person> <person name="charlie"> <child ref="../../person" />
2
by: Sylvia | last post by:
Hi, I'm trying to render a XML structure to HTML using XSLT. My XML describe the header of a table with a complex and not linear structure. The first row of the header table always contains the...
4
by: Alexis | last post by:
Hi, I need to transform one xml document into a second xml document. They both have many nodes so xslt works fine, but there is one node I have not figure out how to transform. Here it is:...
3
by: 胡岳偉(Yueh-Wei Hu) | last post by:
Hi all, I have 2 questions about template function as friends in template classes. I don't know why, and hope someone could help me. ...
0
by: Yueh-Wei Hu | last post by:
Victor Bazarov <v.Abazarov@comAcast.net> wrote in message news: ============================================================== > > Question 1: > >...
8
by: Douglas | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hello, The following code does not compile if line 3 is uncommented "using namespace std". I do not understand it. Could...
3
by: bloc | last post by:
I am programming an interactive CV using xml, xslt and java script. The page consists of a header which contains links to various 'sections' on the xml cv, a left and right menu, and a central...
5
by: Gianni Mariani | last post by:
I'm hoping someone can tell me why using member address of works and why using the dot operator does not in the code below. The code below uses the template function resolution mechanism to...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.