xalan-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kesh...@us.ibm.com
Subject Re: XPath expression in literal element namespace declaration
Date Mon, 13 May 2013 13:18:21 GMT
> Is there a restriction for using XPath expressions for namespace 
declarations in the result document?

Literal namespace declarations are just that, literal namespace 
declarations. 

In XSLT 1.0, there really isn't an explicit way to create "namespace 
nodes" programmatically. The closest you can come is creating a nodeset 
containing an element which is in that namespace (which can be done) and 
then access the nodeset to find that Namespace Node and copy it into the 
target document. There should be an example of that in Dave Pawson's XSL 
FAQ website; I don't have a pointer handy right now.

XSLT 2.0 introduced a better mechanism, the <xsl:namespace> directive. 


______________________________________
"Everything should be as simple as possible. But not simpler." -- 
attributed to Albert Einstein

Csaba Koncz <csabakoncz@gmail.com> wrote on 05/13/2013 04:48:53 AM:

> From:
> 
> Csaba Koncz <csabakoncz@gmail.com>
> 
> To:
> 
> j-users@xalan.apache.org, 
> 
> Date:
> 
> 05/13/2013 04:47 AM
> 
> Subject:
> 
> XPath expression in literal element namespace declaration
> 
> Hi all,
> 
> I need to generate a number of XML Schemas having some XML documents
> as input (crazy, I know).
> 
> This is how I try to generate the root element of the schema:
> 
>     <xsl:param name="targetNS">http://a.com</xsl:param>
> 
>     <xsl:template match="/">
>         <schema xmlns="http://www.w3.org/2001/XMLSchema"
>                 xmlns:tns="{$targetNS}"
>                 targetNamespace="{$targetNS}">
>         </schema>
>     </xsl:template>
> 
> 
> Unfortunately the "{$targetNS}" expression in the xmln:tns attribute
> is not evaluated, thus the created schema is unusable (I can not
> reference types created for the target namespace).
> 
> The other way would be to declare the target namespace as the default
> one in the schema, but that also fails.
> 
> Is there a restriction for using XPath expressions for namespace
> declarations in the result document?
> 
> Is there a way to a achieve my goal to generate a namespace
> declaration which is unknown at the time of writing the XSLT?
> 
> Thank you in advance,
> Csaba
> 
> p.s. I am attaching the XSLT, a sample input and the generated output 
files.
> [attachment "in.out.xml" deleted by Joseph Kesselman/Watson/IBM] 
> [attachment "in.xml" deleted by Joseph Kesselman/Watson/IBM] 
> [attachment "schema-gen.xslt" deleted by Joseph Kesselman/Watson/IBM] 
Mime
View raw message