I have problems to find a good Javascript library to transform XML (in this case, XSD) to XML by XSL. I found some Javascript libraries online, but none of them is working.. I tried to transform it online (by 'http://www.freeformatter.com/xsl-transformer.html'), and that actually works! But when I use a Javascript library, it does not work unfortunately.. What am I doing wrong here?
This is code I have now:
<html>
<body>
<div id="output"></div>
<script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="jquery.xslt.js"></script>
<script type="text/javascript">
$(function() {
$('#output').xslt({xmlUrl: 'notworking.xsd', xslUrl: 'notworking.xsl'});
});
</script>
</body>
</html>
the 'notworking.xsd' file:
<xs:import schemaLocation="https://www.w3.org/2001/xml.xsd" namespace="http://www.w3.org/XML/1998/namespace"/>
<xs:element name="list">
<xs:complexType>
<xs:complexContent>
<xs:extension>
<xs:sequence>
<xs:element minOccurs="0" name="list.start" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
the 'notworking.xsl' file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" version="1.0" indent="yes" encoding="utf-8"/>
<xsl:template match="xs:schema">
<xsl:variable name="name" select="fn:distinct-values(.//xs:element/@name)"/>
<xsl:variable name="schema" select="."/>
<xsl:element name="xsd">
<xsl:for-each select=".//xs:element[@name]">
<xsl:sort select="@name"/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template match="xs:element">
<xsl:variable name="type" select="fn:tokenize(@type,':')[last()]"/>
<xsl:variable name="base" select="fn:tokenize(ancestor::xs:schema/xs:complexType[@name=$type]/xs:complexContent/xs:extension/@base,':')[last()]"/>
<xsl:element name="{@name}">
<xsl:copy-of select="@minOccurs"/>
<xsl:variable name="sequence" select="./xs:complexType/xs:sequence/xs:element|ancestor::xs:schema/xs:complexType[@name=$type]//xs:extension/xs:sequence/xs:element"/>
</xsl:element>
</xsl:template>
<xsl:template match="text()">
<xsl:if test="normalize-space() ne ''">
<xsl:value-of select="."/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>