You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Christian Sell <ch...@netcologne.de> on 2003/10/03 01:22:38 UTC
problem generating XML schema
Hello all,
I am trying to generate an XML schema file from an XML input document,
and encounter a somewhat esoteric problem. The input document is in
essence a simplified version of the schema. Heres an example:
the input:
<library prefix="test">
<element name="dosome"/>
</library>
should become:
<xs:schema xmlns:xs="..." xmlns="test" targetNamespace="test">
<xs:element name=dosome type="ElementType"/>
<... type declaration ..>
</xs:schema>
So far all goes well, with the exception of the "xmlns" attribute in the
output "xs:schema" element, which should hold the value of the "prefix"
attribute from the "library" input element. I am trying to achieve this
with the following literal result element inside the template that
matches the library element:
<xs:schema xmlns="{@prefix}" targetNamespace="{@prefix}">
...
</xs:schema>
(XML schema requires both the xmlns and the targetNamespace attributes
to hold the same value). However, the result I get is:
<xs:schema xmlns="{@prefix}" targetNamespace="test">
Note that the value expression was resolved for the targetNamespace
attribute, but not for the xmlns attribute.
Is this an error with Xalan, or am I missing something? Does anyone have
a suggestion how to achieve the desired result?
TIA,
Christian
Re: problem generating XML schema
Posted by Christian Sell <ch...@netcologne.de>.
Santiago,
you are confirming my fears. Anyway, thanks for reading and answering my
mail.
I have tried fiddling with Xalan java extension functions, but the way
seems to be thoroughly blocked. What a misery. This seemed like such an
obvious application for XSLT.
Christian
Santiago Pericas-Geertsen wrote:
> Christian,
>
> The problem here is that since the stylesheet is itself an XML
> document, the redefinition of the default namespace in <xs:schema ...>
> is actually processed by the parser before it gets to the XSLT
> processor. Hence, its value is taken literally and never evaluated.
>
> The generation of arbitrary ns declarations is not supported in XSLT
> 1.0. What you should do is generate elements/attributes with a non-null
> URI and let the system allocate the prefixes for you. Unfortunately,
> this is not a good solution in all cases (and yours may be one of them).
>
> The are some hacks that you can try but they are not going to work for
> all processors. For example, in XSLTC you can fool the system using
> xsl:attribute as follows,
>
> <xsl:attribute name="{'xmlns'}">someURI</xsl:attribute>
>
> Note the use of "{}" to turn the value into an expression (if it is
> just a literal it will be flagged as an error). I believe that Xalan, on
> the other hand, will report an error in this case too.
>
> Hope this helps.
>
> -- Santiago
>
> On Thu, 2003-10-02 at 19:22, Christian Sell wrote:
>
>>Hello all,
>>
>>I am trying to generate an XML schema file from an XML input document,
>>and encounter a somewhat esoteric problem. The input document is in
>>essence a simplified version of the schema. Heres an example:
>>
>>the input:
>>
>><library prefix="test">
>> <element name="dosome"/>
>></library>
>>
>>should become:
>>
>><xs:schema xmlns:xs="..." xmlns="test" targetNamespace="test">
>> <xs:element name=dosome type="ElementType"/>
>>
>> <... type declaration ..>
>></xs:schema>
>>
>>So far all goes well, with the exception of the "xmlns" attribute in the
>>output "xs:schema" element, which should hold the value of the "prefix"
>>attribute from the "library" input element. I am trying to achieve this
>>with the following literal result element inside the template that
>>matches the library element:
>>
>><xs:schema xmlns="{@prefix}" targetNamespace="{@prefix}">
>> ...
>></xs:schema>
>>
>>(XML schema requires both the xmlns and the targetNamespace attributes
>>to hold the same value). However, the result I get is:
>>
>><xs:schema xmlns="{@prefix}" targetNamespace="test">
>>
>>Note that the value expression was resolved for the targetNamespace
>>attribute, but not for the xmlns attribute.
>>
>>Is this an error with Xalan, or am I missing something? Does anyone have
>>a suggestion how to achieve the desired result?
>>
>>TIA,
>>Christian
>>
>
>
>
Re: problem generating XML schema
Posted by Santiago Pericas-Geertsen <Sa...@sun.com>.
Christian,
The problem here is that since the stylesheet is itself an XML
document, the redefinition of the default namespace in <xs:schema ...>
is actually processed by the parser before it gets to the XSLT
processor. Hence, its value is taken literally and never evaluated.
The generation of arbitrary ns declarations is not supported in XSLT
1.0. What you should do is generate elements/attributes with a non-null
URI and let the system allocate the prefixes for you. Unfortunately,
this is not a good solution in all cases (and yours may be one of them).
The are some hacks that you can try but they are not going to work for
all processors. For example, in XSLTC you can fool the system using
xsl:attribute as follows,
<xsl:attribute name="{'xmlns'}">someURI</xsl:attribute>
Note the use of "{}" to turn the value into an expression (if it is
just a literal it will be flagged as an error). I believe that Xalan, on
the other hand, will report an error in this case too.
Hope this helps.
-- Santiago
On Thu, 2003-10-02 at 19:22, Christian Sell wrote:
> Hello all,
>
> I am trying to generate an XML schema file from an XML input document,
> and encounter a somewhat esoteric problem. The input document is in
> essence a simplified version of the schema. Heres an example:
>
> the input:
>
> <library prefix="test">
> <element name="dosome"/>
> </library>
>
> should become:
>
> <xs:schema xmlns:xs="..." xmlns="test" targetNamespace="test">
> <xs:element name=dosome type="ElementType"/>
>
> <... type declaration ..>
> </xs:schema>
>
> So far all goes well, with the exception of the "xmlns" attribute in the
> output "xs:schema" element, which should hold the value of the "prefix"
> attribute from the "library" input element. I am trying to achieve this
> with the following literal result element inside the template that
> matches the library element:
>
> <xs:schema xmlns="{@prefix}" targetNamespace="{@prefix}">
> ...
> </xs:schema>
>
> (XML schema requires both the xmlns and the targetNamespace attributes
> to hold the same value). However, the result I get is:
>
> <xs:schema xmlns="{@prefix}" targetNamespace="test">
>
> Note that the value expression was resolved for the targetNamespace
> attribute, but not for the xmlns attribute.
>
> Is this an error with Xalan, or am I missing something? Does anyone have
> a suggestion how to achieve the desired result?
>
> TIA,
> Christian
>