views:

1252

answers:

2

I wanna create an element in my XSL 1.0 with some namespace Just like this:

<element xmlns:a = '...' xmlns:b = '...' xmlns = '...' >

For some reason I can't use XSL 2.0, with <xsl:namespace> extension, there is only one allowed namespace declared for each element in XSL 1.0,how should I do?

Regards,

A: 

Works for me.

If I make the file test.xsl :

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

<xsl:template match="/">
    <root>
        <multins xmlns:abc="http://example.com/1" xmlns:def="http://example.com/2" />
    </root>
</xsl:template>

</xsl:stylesheet>

And then run it

xsltproc test.xsl test.xsl
<?xml version="1.0"?>
<root><multins xmlns:abc="http://example.com/1" xmlns:def="http://example.com/2"/&gt;&lt;/root&gt;

with this version info :

$ xsltproc --version
Using libxml 20703, libxslt 10124 and libexslt 813
xsltproc was compiled against libxml 20632, libxslt 10124 and libexslt 813
libxslt 10124 was compiled against libxml 20632
libexslt 813 was compiled against libxml 20632
Paul Tarjan
Actually I transform the XSL in a c# program for some reason. The result is not the same as yours
abusemind
A: 

Try the W3C XSLT 2.0 Spec: Creating Namespace Nodes. The gist of it is that you can create elements within other elements to put those namespaces into scope.

Example:

<!--XSLT 2.0-->
<data xsi:type="xs:integer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  <xsl:namespace name="xs" select="'http://www.w3.org/2001/XMLSchema'"/&gt;
  <xsl:text>42</xsl:text>
</data>

<!--XSLT 1.0-->
<data xsi:type="xs:integer"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  42
</data>
TahoeWolverine
yeah I know that the XSL 2.0 supports the < xsl: namespace > extension
abusemind
For I transform the XSL in the c# program, which doesn't support XSL 2.0 in its System.xml.xsl namespace, so XSL 1.0 is the only choice
abusemind
It sounds like you've answered your question, so you should post an answer of your own.
TahoeWolverine