Based on one of the solutions provided on SO regarding serialization in XSLT: How to convert XML Node to String, I'm trying to serialize something like this.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" elementFormDefault="qualified">
<xs:annotation>
<xs:documentation>
Package Name: Master
version: 2
Description:
This is a dummy description used for testing purposes.
</xs:documentation>
</xs:annotation>
<!-- ********************************************************************************************************************
*** Includes
*************************************************************************************************************************-->
<!-- Basic Layer -->
<xs:include schemaLocation="dummy1.xsd"/>
<xs:include schemaLocation="dummy2.xsd"/>
<!-- ********************************************************************************************************************
*** Simple Types
*************************************************************************************************************************-->
<xs:simpleType name="YESNO">
<xs:restriction base="xs:string">
<xs:enumeration value="YES"/>
<xs:enumeration value="NO"/>
</xs:restriction>
</xs:simpleType>
<!-- ********************************************************************************************************************
*** Simple Types
*************************************************************************************************************************-->
<xs:complexType name="Custom" xdb:SQLType="L2A_CUSTOM_OT">
<xs:sequence>
<xs:element name="Postal" type="TPostal" />
<xs:element name="Entry" type="Entry" minOccurs="0" maxOccurs="8" />
</xs:sequence>
</xs:complexType>
</xs:schema>
As I'm just beginning with XSLT, I can't seem to find a solution that also includes namespaces and comments. Trying to include everything as-is without any loss of info, I came up with this XSLT.
<xsl:variable name="xsdresultstring">
<xsl:apply-templates select="$xsdresult" mode="serialize"/>
</xsl:variable>
<!-- any element -->
<xsl:template match="*" mode="serialize">
<xsl:text><</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="serialize" />
<xsl:choose>
<xsl:when test="node()">
<xsl:text>></xsl:text>
<xsl:apply-templates mode="serialize" />
<xsl:text></</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>></xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> /></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Attributes -->
<xsl:template match="@*" mode="serialize">
<xsl:text> </xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>="</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
</xsl:template>
<xsl:template match="text()" mode="serialize">
<xsl:value-of select="." />
</xsl:template>