How do I transform this xml file into html by using this xslt document

T

Tony

Hello!

I know that this isn't 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 can't 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:blush:utput 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'm missing here ?


<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="book.xsl"?>
<books>
<book>
<chapter number="1">This is the first chapter</chapter>
<chapter number="2">This is the second chapter</chapter>
<chapter number="3">This is the third chapter</chapter>
<chapter number="4">This is the fourth chapter</chapter>
<chapter number="5">This is the fifth chapter</chapter>
</book>
</books>

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

<xsl:template match="/">
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
<xsl:apply-templates select="/Book/Chapter" />
</body>
</html>
</xsl:template>

<xsl:template match="Chapter">
<xsl:if test="position()=2">
<p>When the context node is the second <b>Chapter</b> element node
then </p>
<p>the context position is <xsl:value-of select="position()" /></p>
<p>and the context size is <xsl:value-of select="last()" /></p>
<p>The text the <b>Chapter</b> element node contain is <xsl:value-of
select="." /></p>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
 
A

Arne Vajhøj

I know that this isn't 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 can't 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:blush:utput 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'm missing here ?


<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="book.xsl"?>
<books>
<book>
<chapter number="1">This is the first chapter</chapter>
<chapter number="2">This is the second chapter</chapter>
<chapter number="3">This is the third chapter</chapter>
<chapter number="4">This is the fourth chapter</chapter>
<chapter number="5">This is the fifth chapter</chapter>
</book>
</books>

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

<xsl:template match="/">
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
<xsl:apply-templates select="/Book/Chapter" />
</body>
</html>
</xsl:template>

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

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:

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

<xsl:template match="/">
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
<xsl:apply-templates select="/books/book/chapter" />
</body>
</html>
</xsl:template>

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

</xsl:stylesheet>

because element names are case sensitive.

Arne
 
T

Tony

Arne Vajhøj said:
I know that this isn't 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 can't 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:blush:utput 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'm missing here ?


<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="book.xsl"?>
<books>
<book>
<chapter number="1">This is the first chapter</chapter>
<chapter number="2">This is the second chapter</chapter>
<chapter number="3">This is the third chapter</chapter>
<chapter number="4">This is the fourth chapter</chapter>
<chapter number="5">This is the fifth chapter</chapter>
</book>
</books>

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

<xsl:template match="/">
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
<xsl:apply-templates select="/Book/Chapter" />
</body>
</html>
</xsl:template>

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

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:

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

<xsl:template match="/">
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
<xsl:apply-templates select="/books/book/chapter" />
</body>
</html>
</xsl:template>

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

</xsl:stylesheet>

because element names are case sensitive.

Arne

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.
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
</body>
</html>


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
 
A

Arne Vajhøj

Arne Vajhøj said:
I know that this isn't 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 can't 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:blush:utput 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'm missing here ?


<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="book.xsl"?>
<books>
<book>
<chapter number="1">This is the first chapter</chapter>
<chapter number="2">This is the second chapter</chapter>
<chapter number="3">This is the third chapter</chapter>
<chapter number="4">This is the fourth chapter</chapter>
<chapter number="5">This is the fifth chapter</chapter>
</book>
</books>

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

<xsl:template match="/">
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
<xsl:apply-templates select="/Book/Chapter" />
</body>
</html>
</xsl:template>

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

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:

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

<xsl:template match="/">
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
<xsl:apply-templates select="/books/book/chapter" />
</body>
</html>
</xsl:template>

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

</xsl:stylesheet>

because element names are case sensitive.

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.
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
</body>
</html>


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 ?

Difficult to say.

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

<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
<p>When the context node is the second <b>Chapter</b> element node
then </p>

<p>the context position is 2</p>
<p>and the context size is 5</p>
<p>The text the <b>Chapter</b> element node contain is This is the
second ch
apter</p>
</body>
</html>

I think you have changed something!

Arne
 
T

Tony

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
-------------------
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="book.xsl"?>
<books>
<book>
<chapter number="1">This is the first chapter</chapter>
<chapter number="2">This is the second chapter</chapter>
<chapter number="3">This is the third chapter</chapter>
<chapter number="4">This is the fourth chapter</chapter>
<chapter number="5">This is the fifth chapter</chapter>
</book>
</books>

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

<xsl:template match="/">
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
<xsl:apply-templates select="/Book/Chapter" />
</body>
</html>
</xsl:template>

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

Could the reason that it doesn't work for me that there is some reference
library that is missing.
I still only get this when I run the program
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
</body>
</html>

Have you any idea what it might be ?

//Tony
 
A

Arne Vajhøj

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
-------------------
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="book.xsl"?>
<books>
<book>
<chapter number="1">This is the first chapter</chapter>
<chapter number="2">This is the second chapter</chapter>
<chapter number="3">This is the third chapter</chapter>
<chapter number="4">This is the fourth chapter</chapter>
<chapter number="5">This is the fifth chapter</chapter>
</book>
</books>

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

<xsl:template match="/">
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
<xsl:apply-templates select="/Book/Chapter" />
</body>
</html>
</xsl:template>

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

Could the reason that it doesn't work for me that there is some
reference library that is missing.
I still only get this when I run the program
<html>
<head>
<title>This shows the context position and context size</title>
</head>
<body>
<h3>Context position and context size demo.</h3>
</body>
</html>

Have you any idea what it might be ?

# <book>

# <chapter number="2">

lowercase b and c

# <xsl:apply-templates select="/Book/Chapter" />

uppercase B and C

That does not match!

Arne
 
T

Tony

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 doesn't 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
 
A

Arne Vajhøj

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 doesn't exist in VS2010 ?
Is it some settings that is needed perhaps ?

No idea.

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

:)

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top