简体   繁体   中英

XSL element with multiple namespace with different prefix

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,

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

<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"/></root>

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

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">
  <xsl:namespace name="xs" select="'http://www.w3.org/2001/XMLSchema'"/>
  <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">
  42
</data>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM