473,396 Members | 2,037 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,396 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 4256
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.