daldridge@gmail.com wrote:
[color=blue]
> Suppose I have this XML input:
>
> <Foo>
> <Bar>Baz</Bar>
> </Foo>
>
>
> What I'd like to generate (ignore any <xs:include> requirements) is:
>
> <xs:element ref="Baz:Baz" xmlns:Baz="A:B:C:Baz"/>[/color]
Most can be simply done with
<xsl:template match="Foo">
<xs:element
xmlns:xs="http://www.w3.org/2001/XMLSchema"
ref="{Bar}:{Bar}" />
</xsl:template>
The xmlns:Baz="A:B:C:Baz" will be tricky however as namespace
declarations in terms of the XSLT/XPath tree model are not attributes.
I am not sure that there is a way with XSLT 1.0 to achieve what you
want, if the prefix and value are to be generated from the source input.
If it were static you could simply do e.g.
<xsl:template match="Foo">
<xs:element
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:Baz="A:B:C:Baz"
ref="{Bar}:{Bar}" />
</xsl:template>
See also <http://www.dpawson.co.uk/xsl/sect2/N5536.html#d6476e2293>
which suggests XSLT 2.0 has a solution.
There you could do e.g.
<xsl:template match="Foo">
<xs:element
xmlns:xs="http://www.w3.org/2001/XMLSchema"
ref="{Bar}:{Bar}">
<xsl:namespace name="{Bar}"><xsl:value-of select="concat('A:B:C:',
Bar)" /></xsl:namespace>
</xs:element>
</xsl:template>
and the result is
<xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:Baz="A:B:C:Baz" ref="Baz:Baz"/>
http://www.saxonica.com/ provides an XSLT 2.0 processor.
--
Martin Honnen
http://JavaScript.FAQTs.com/