.NET Framework - How do I transform this xml file into html by using this xslt document

Asked By Tony on 18-Feb-12 02:36 PM
Hello!

I know that this is not the right forum but I hope someone know this anyway.
I have one xml file and one xslt file shown below.
I want to transform this xml file into html by using this xslt document but
I cannot find out why the html is not being created.

Here is the documentation I have found
How to: Execute an XSLT Transformation from the XML Editor
Visual Studio 2010 Other Versions  Visual Studio 2008
Visual Studio 2005
0 out of 1 rated this helpful Rate this topic
The XML Editor allows you to associate an XSLT style sheet with an XML
document, perform the transformation, and view the output. The resulting
output from the XSLT transformation is displayed in a new document window.

The Output property specifies the filename for the output. If the Output
property is blank, a filename is generated in your temporary directory. The
file extension is based on the xsl:output element in your style sheet and
can be .xml, .txt or .htm.

If the Output property specifies a filename with an .htm or .html extension,
the XSLT output is previewed using Microsoft Internet Explorer. All other
file extensions are opened using the default editor chosen by Microsoft
Visual Studio. For example, if the file extension is .xml, Visual Studio
uses the XML Editor.

To execute an XSLT transformation from an XML document
Open an XML document in the XML Editor.

Associate an XSLT style sheet with the XML document.

Add an xml-stylesheet processing instruction to the XML document. For
example, add the following line <?xml-stylesheet type='text/xsl'
href='filename.xsl'?> to the document prolog.

-or-

Add the XSLT style sheet using the Properties window. In the document
Properties Window, click the Browse button for the Stylesheet field, select
the XSLT style sheet, and click Open.

Click the Show XSL Output button on the XML Editor toolbar.

There is no Show XSL Output  in the XML tool button.
I use VS 2010 professional.
Can somebody explain what I am missing here ?



xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


then </p>
select="." /></p>




Arne_Vajhøj replied to Tony on 18-Feb-12 05:33 PM
Use C# !


using System;
using System.Xml;
using System.Xml.Xsl;

namespace E
{
public class Program
{
public static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("tony.xml");
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("tony.xsd");
XmlTextWriter wrt = new XmlTextWriter(Console.Out); //
should probably be a StreamWriter in real code
wrt.Formatting = Formatting.Indented;
xslt.Transform(doc, wrt);
Console.ReadKey();
}
}
}

and you will need to change the XSL to:

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


then </p>


because element names are case sensitive.

Arne
Tony replied to Arne_Vajhøj on 18-Feb-12 08:04 PM
The output from the transformation is not what is shown in a book I read.
When I run the example program you send me it showed this.


But the output in the book is this
Context position and context size demo
When the context node is the second Chapter element node then
the contect position is 2
and the context size is 5
The text the Chapter element node contains is "This is the second chapter"

What is it that I have missed now ?

//Tony
Arne_Vajhøj replied to Tony on 18-Feb-12 08:13 PM
Difficult to say.

When I run that code with that XSD and the original XML I get:

then </p>

second ch
apter</p>

I think you have changed something!

Arne
Tony replied to Arne_Vajhøj on 18-Feb-12 08:33 PM
This is strange. Here is the code I use that you send me.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Xsl;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load(@"c:\users\tony\documents\visual studio
2010\Projects\ConsoleApplication1\ConsoleApplication1\book.xml");
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(@"c:\users\tony\documents\visual studio
2010\Projects\ConsoleApplication1\ConsoleApplication1\book.xsl");
XmlTextWriter wrt = new XmlTextWriter(Console.Out); //
//should probably be a StreamWriter in real code
wrt.Formatting = Formatting.Indented;
xslt.Transform(doc, wrt);
Console.ReadKey();
}
}
}


Here is the Xml file
-------------------

Here is the Xsl file
------------------
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


When the context node is the second <b>Chapter</b> element node then
the context position is <xsl:value-of select="position()" />
and the context size is <xsl:value-of select="last()" />
The text the <b>Chapter</b> element node contain is <xsl:value-of
select="." />

Could the reason that it does not work for me that there is some reference
library that is missing.
I still only get this when I run the program

Have you any idea what it might be ?

//Tony
Arne_Vajhøj replied to Tony on 18-Feb-12 08:46 PM
lowercase b and c


uppercase B and C

That does not match!

Arne
Tony replied to Tony on 18-Feb-12 08:50 PM
Now it work!

//Tony
Tony replied to Arne_Vajhøj on 18-Feb-12 09:08 PM
It works now but I just wonder why is the XML tool bar so different between
VS 2005 and VS 2010
I had an old VS 2005 that I installed and in this version there is an Show
XSLT output
in the XML toolbar.
Have you any idea why this alternative does not exist in VS2010 ?
Is it some settings that is needed perhaps ?

The result running C# and VS 2005 show XSLT output give the same result.

//Tony
Arne_Vajhøj replied to Tony on 18-Feb-12 09:15 PM
No idea.

But I do know that there are plenty of XML/XSLT tools around.


Arne
Arne_Vajhøj replied to Tony on 18-Feb-12 09:16 PM
XML is case sensitive, so you need to match exactly.

Arne