创建xmlns:xsi命名空间和属性

我想创建以下元素:
<exercises xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mySchema.xsd">

如果我使用这样的东西:

<xsl:element name="excercises">
<xsl:attribute name="xmlns:xsi" namespace="http://www.w3.org/2001/XMLSchema-instance"/>

然后它创建这样的soemthing:

<excercises xp_0:xsi="" xmlns:xp_0="http://www.w3.org/2001/XMLSchema-instance">

哪些看起来不像我想要的?

尝试以下代替:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="@* | node()">
        <xsl:apply-templates select="xml"></xsl:apply-templates>
    </xsl:template>

    <xsl:template match="xml">
        <xsl:element name="exercises">
            <xsl:attribute name="xsi:noNamespaceSchemaLocation">mySchema.xsd</xsl:attribute>
            some value
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

关键是在声明中声明xsi命名空间.

我刚刚做了模板比赛,只是为了测试.

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念