Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create xmlns:xsi namespace and attribute

I want to create the following element:

<exercises xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mySchema.xsd">

If I use something like this:

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

Then it creates soemthing like this:

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

Which doesn't look like what I want...

like image 952
eddy147 Avatar asked Jan 08 '09 13:01

eddy147


1 Answers

Try the following instead:

<?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>

The key concern is to declare the xsi namespace in the declaration.

I've just made up the template match on just to test.

like image 66
Kev Avatar answered Oct 25 '22 08:10

Kev