Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using xsl to transform .xsd files to a xml file 1

Status
Not open for further replies.

chrislx

Programmer
Oct 17, 2003
32
0
0
US
There are several schema files, one schema file includes several other schema files. For example,
<xs:include schemaLocation="C:\myCodes.xsd"/>. I would like to transform the schema files into a xml file.

Question:
How can I use xslt to get the nodes and attributes which are in the included files? I have tried to use <xsl:foreach select="document(myCodes.xsd)\xs:complexType") and I could not get it work.

Thanks in advance.

chrislx
 
When I use imports like these, I always stuff them in threads incase you want to pull more data out of the file later in different XPath statements. That way you don't have to do the document statement over and over. Anyways, I have a simple xml file, xsd file, and a xsl file example.

This xml is from my JFaceDBc plugin for eclipse.
Code:
<Beans>
    <Bean Class="net.sourceforge.squirrel_sql.fw.sql.SQLAlias">
        <activate>false</activate>
        <driverIdentifier Class="net.sourceforge.squirrel_sql.fw.id.UidIdentifier">
            <string>-4</string>
        </driverIdentifier>
        <identifier Class="net.sourceforge.squirrel_sql.fw.id.UidIdentifier">
            <string>aasdf</string>
        </identifier>
        <name>asdf</name>
        <password>asdf</password>
        <url>asdf</url>
        <userName>asdf</userName>
    </Bean>
</Beans>


<xs:schema xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]
<xs:element name="selfTest">
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]
    <xsl:variable name="schema" select="document('selfTest.xsd')"/>
    <xsl:template match="/">
        <Beans>
            <xsl:for-each select="Beans/Bean">
                <xsl:sort select="name"/>
                <xsl:copy-of select="."/>
            </xsl:for-each>
            <xsl:value-of select="$schema/xs:schema/xs:element/xs:annotation/xs:documentation"/>
        </Beans>
    </xsl:template>
</xsl:stylesheet>

-jay
 
Thanks for the big help. It works well.

chrislx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top