XSLT Template from XSD?

Posted on 2014-02-17
Last Modified: 2014-02-18

Are there any tools  I can use in .NET that ingest an XSD to generate a template for use in an XSLT?

Question by:jdannemann
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 35

Expert Comment

ID: 39866586
I'm not sure exactly what you would expect to see in a template XSLT based on the details of an XSD. Can you provide a simplified example of what you would expect to happen? ie. give a simple XSD and what XSLT you would expect to get.

Author Comment

ID: 39868248
Thanks for the response mccarl.

I am really looking for something pretty simple here. Taking the standard sitemap.xsd for an example (, I would expect the output template to look something like this:

    <xsl:template match="/">

Open in new window

The template it outputs does not require functionality, but rather it's purpose is for providing a starting point for our developers. Some of the XML formats we deal with are very complex and contain hundreds of element definitions, and so it is my hope to locate tool or library that will help us auto-generate the code and speed up the development process.
LVL 45

Accepted Solution

aikimark earned 500 total points
ID: 39868335
Using XMLPad, I opened your XSD file (URL) and then did an XML | Generate sample XML file operation.

Selecting Generate non-mandatory attributes and elements and a Repeat count=1, the following was produced:
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns=""
   xsi:schemaLocation=" file:///C:/Users/Mark/AppData/Local/Microsoft/Windows/Temporary%20Internet%20Files/Content.IE5/05CKYW7W/sitemap%5B1%5D.xsd">

Open in new window


Author Comment

ID: 39868522
LVL 35

Expert Comment

ID: 39869086
Depending on how advanced that you want it to be, you can do something yourself quite easily. Your input (XSD) and output (XSL) are both XML format so you can use XSL itself to generate an output stylesheet. Take this fairly simple example, it works with the sitemap XSD that you referred to. The great thing about it is that you can customise it to produce almost anything that you want or to cater for lots of different types of input. Just a thought...
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="" xmlns:xsd="">
<xsl:output method="xml" indent="yes" />

<xsl:template match="/xsd:schema">
	<xsl:element name="xsl:stylesheet" namespace="">
	<xsl:attribute name="version">1.0</xsl:attribute>
	<xsl:element name="xsl:template" namespace="">
	<xsl:attribute name="match">/</xsl:attribute>
	<xsl:apply-templates select="xsd:element" />

<xsl:template match="xsd:element">
	<xsl:element name="{@name}" namespace="{/xsd:schema/@targetNamespace}">
			<xsl:when test="@type">
	    		<xsl:apply-templates select="//xsd:complexType[@name = current()/@type]//xsd:element" />
		   		<xsl:apply-templates select="xsd:complexType//xsd:element" />

Open in new window


Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Hive vs Impla in Hadoop 1 75
C# Service FileSystemwatcher isse 9 46
Data organization issue 7 37
Retreiving SOAP FAULT messages using classical ASP 14 29
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question