Skip to content Skip to navigation

OpenStax_CNX

You are here: Home » Content » XSLT transform GUI with SharpDevelop IDE

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

In these lenses

  • XSLT display tagshide tags

    This module is included inLens: Hannes Hirzel's XSLT Lens
    By: Hannes Hirzel

    Comments:

    "How to write a simple C# GUI to do XSLT transformations."

    Click the "XSLT" link to see all content selected in this lens.

    Click the tag icon tag icon to display tags associated with this content.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.
 

XSLT transform GUI with SharpDevelop IDE

Module by: Hannes Hirzel. E-mail the author

Summary: It is shown how to program a simple GUI with SharpDevelop to do XSLT transforms.

Introduction

In this module a simple GUI for doing XSLT transforms is created. The IDE used is SharpDevelop, the language is C-Sharp. In another module the code is converted to VB.net, see links section.

The module is in a draft stage at the moment. It probably gives enough details for some readers. For others there might not be enough information to recreate the example. In that case please do not hesitate to write an email to the author asking for clarification.

Create the XSLT transform GUI

Start the IDE. Choose 'File' / 'New Solution', then 'Windows Application'. Then give a name and click 'Create'. You should now have what the screen shot below shows.

XSLTtransformScreen1-After-Creation-Of-Project.PNG

Click on 'Design' on the tab below the MainForm, if necessary choose 'Properties' from the 'View' menu to get a properties window.

XSLTtransformScreen2-GUI-Layout.PNG

Create the following GUI elements

  • textBoxXSLT
  • textBoxInputXML
  • textBoxResult
  • buttonXSLT
  • buttonClose

For the text boxes set the property multiline to true.

You might also want to set maxlength of the text boxes to a higher number, e.g. 1000000.

Then adapt the code that the text boxes are initialized and the XSLT button does an XSLT transform as shown below. (MORE EXPLANATIONS NEEDED)

/*
 * Created by SharpDevelop.
 * User: hirzel
 * Date: 09/05/2012
 * Time: 06:03
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Xml.Xsl;

namespace XSLTtransform
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
			if (File.Exists("transform.xsl")) {
				StreamReader sr = new StreamReader("transform.xsl");
				this.textBoxXSLT.Text = sr.ReadToEnd();
				sr.Close();
			};
			buttonXSLT.Select();
		}
		
		
		
		
		void ButtonXSLTClick(object sender, EventArgs e)
		{
			// Console.Write(Path.GetTempPath());
			StreamWriter sw = new StreamWriter("input.xml");
			sw.Write(textBoxInputXML.Text);
			sw.Close();
			
			sw = new StreamWriter("transform.xsl");
			sw.Write(textBoxXSLT.Text);
			sw.Close();
			
			// Create the XsltSettings object with script enabled.
			
			XsltSettings settings = new XsltSettings(false,true);

			// Execute the transform.
			try {
			  XslCompiledTransform xslt = new XslCompiledTransform();
			xslt.Load("transform.xsl", settings, new System.Xml.XmlUrlResolver());
			xslt.Transform("input.xml", "output.xml");
			
			StreamReader sr = new StreamReader("output.xml");
			textBoxResult.Text = sr.ReadToEnd();
			sr.Close();
			} catch (Exception ex) {
				MessageBox.Show(ex.Message);
			
		}
	}
		
		void Button2Click(object sender, EventArgs e)
		{
			this.Close();
		}
}
}

The working program

Screen shot of the GUI in action

Content actions

Download module as:

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks