Generate XSD with XSLT and XML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lskov
    New Member
    • Apr 2007
    • 14

    Generate XSD with XSLT and XML

    Hey

    Im really new to XML and cant find a way how to not have xmlns as an attribute en every element.

    The xslt code is:
    <xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
    <xsl:output method="xml" />



    <xsl:template match="/">
    <xsl:element name ="ConfigData " namespace="http ://www.w3.org/2001/XMLSchema-instance">
    <xsl:element name ="VariableSecti on">
    <xsl:text>&#xA; &#xA;</xsl:text>

    <xsl:for-each select="ConfigD ata/VariableSection/Variable">

    <xsl:element name="xs:enumer ation">
    <xsl:attribut e name="value">
    <xsl:value-of select="Softwar eName"></xsl:value-of>
    </xsl:attribute>
    </xsl:element>

    <xsl:text>&#xA; </xsl:text>
    </xsl:for-each>
    </xsl:element>
    </xsl:element>
    </xsl:template>

    </xsl:stylesheet>

    -------- And the output is -----

    <?xml version="1.0" encoding="utf-8"?><ConfigD ata xmlns="http://www.w3.org/2001/XMLSchema-instance"><Vari ableSection xmlns="">

    <xs:enumerati on value="VA_Reset WTCCommand_Repl y" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" />
    <xs:enumerati on value="VA_Reset WTCCommand_Repl y" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" />
    <xs:enumerati on value="VA_Reset WTCCommand_Stat us" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" />
    <xs:enumerati on value="VA_GetEv entCommand_Requ est" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" />

    ------------

    How can i remove the xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" from every line so it i general?

    /Lasse
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Instead of declaring your element like so:
    <xsl:element name="xs:enumer ation">

    Declare it like:
    <xsl:element name ="enumeratio n" namespace="http ://www.w3.org/2001/XMLSchema-instance">

    Comment

    Working...