[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: problem - generating XML schema via XSLT

Subject: RE: problem - generating XML schema via XSLT
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 3 Oct 2003 18:08:57 +0100
generate xml attribute xsl
Namespace declarations in the source document are translated by the XML
parser into namespace nodes, they are not treated by XSLT as attribute
nodes. Therefore, a namespace declaration can never contain an attribute
value template (because it isn't an attribute).

You need to produce in the result tree a namespace node whose name
(=prefix) is "" and whose string value (=namespace URI) is "test". (It's
very confusing that you chose to use the name "prefix" to refer to the
namespace URI!

In XSLT 2.0 you can do this with

<xsl:namespace name=""><xsl:value-of select="@prefix"/></xsl:namespace>

In 1.0 there is no direct way of doing this. The nearest equivalent is:

<xsl:variable name="dummy">
  <xsl:element name="e" namespace="{@prefix}"/>
</xsl:variable>

<xsl:copy select="xx:node-set($dummy)/*/namespace::*[.=@prefix]"/>

This creates a dummy element in the required namespace, and then copies
the required namespace node to the result tree.

Michael Kay 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Christian Sell
> Sent: 03 October 2003 15:28
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  problem - generating XML schema via XSLT
> 
> 
> Hello all,
> 
> I am trying to generate an XML schema file from an XML input 
> document, 
> and encounter a somewhat esoteric problem. I am using Xalan 
> 2.5.1. 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
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.