Solved

XSLT Template from XSD?

Posted on 2014-02-17
5
434 Views
Last Modified: 2014-02-18
Hi,

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

Thanks,
Josh
0
Comment
Question by:jdannemann
  • 2
  • 2
5 Comments
 
LVL 35

Expert Comment

by:mccarl
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.
0
 
LVL 1

Author Comment

by:jdannemann
ID: 39868248
Thanks for the response mccarl.

I am really looking for something pretty simple here. Taking the standard sitemap.xsd for an example (http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd), I would expect the output template to look something like this:

    <xsl:template match="/">
      <urlset>
        <url>
          <loc></loc>
          <lastmod></lastmod>
          <changefreq></changefreq>
          <priority></priority>
        </url>
      </urlset>
    </xsl:template>

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.
0
 
LVL 45

Accepted Solution

by:
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="http://www.sitemaps.org/schemas/sitemap/0.9"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 file:///C:/Users/Mark/AppData/Local/Microsoft/Windows/Temporary%20Internet%20Files/Content.IE5/05CKYW7W/sitemap%5B1%5D.xsd">
  <url>
    <loc/>
    <lastmod/>
    <changefreq/>
    <priority/>
  </url>
</urlset>

Open in new window

0
 
LVL 1

Author Comment

by:jdannemann
ID: 39868522
0
 
LVL 35

Expert Comment

by:mccarl
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="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" indent="yes" />

<xsl:template match="/xsd:schema">
	<xsl:element name="xsl:stylesheet" namespace="http://www.w3.org/1999/XSL/Transform">
	<xsl:attribute name="version">1.0</xsl:attribute>
	<xsl:element name="xsl:template" namespace="http://www.w3.org/1999/XSL/Transform">
	<xsl:attribute name="match">/</xsl:attribute>
	<xsl:apply-templates select="xsd:element" />
	</xsl:element>
	</xsl:element>
</xsl:template>

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

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now