PDA

View Full Version : How can I transform a XML file using XSL in VB.NET?


pasquale
07-13-2007, 05:50 PM
Hi everybody, :)

I need your help. I'm working as junior Web Developer. I need urgently your help.... I'm doing my first week probation period... If I will not find the solution of this.. I'll lose my job... Please help me... I think that for a senior .NET developer it's quite easy to do but I don't have any idea how to do it because I have never done it before.... Please send me the solution (even in C#), it will be very apretiate! :)

The problem is quite simple, I have this file:
book.xml

<book>
<chapter>
<para>one</para>
<para>two</para>
<para>three</para>
<para>four</para>
</chapter>
<chapter>
<para>eins</para>
<para>zwei</para>
</chapter>
</book>

and this xsl file:

book.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<xsl:for-each select="book/chapter">

<h1>chapter: <xsl:value-of select="position()" /></h1>
<xsl:apply-templates/>

</xsl:for-each>

</xsl:template>

<xsl:template match="para">
<br>
<xsl:value-of select="." />
</br>
</xsl:template>

</xsl:stylesheet>

How can I load the result of the transformation in a literal:

<div>
<asp:Literal ID="xmlExample" runat="server"></asp:Literal>
</div>

I was trying to write this in the aspx.vb file:

' Create an isntance of XmlTextReader and call Read method to read the(file)
Dim textReader As XmlTextReader = New XmlTextReade("\\public\\xml\\example\\books.xml")
textReader.Read()
.................................................................................................... .

I got a error because It can find the path.... But can the XmlTextReader class transform XSL??? I mean how can I trasnform my XML file using the class textReader? Should I use another class??? :confused:
Why it cannot find the path?? :confused:

My files are located in:

public/xml/book.xml
public/xsl/book.xsl

Many thanks,

I look forward to hearing soon from you.

Please I need your help... :thumbsup: