xsl-list
[Top] [All Lists]

Re: Generating schema target namespaces from XSLT

2002-11-02 13:13:13
Hi Danny,

I can get the targetNamespace attribute set, but becasue the namespace has 
to be identified on the <stylesheet> attribute I can't use a parameter 
there to set this value to be the same - thus I have to hard code it.

I assume you are declaring the namespace on xsl:stylesheet so that it
gets declared on the generated xsd:schema?

If so, then the trick is to create a temporary node with the required
namespace derived from $target, and then copy the namespace node to
the output xsd:schema element.  This requires an extension function,
but I see you are already declaring the saxon namespace.

  <xsl:variable name="ns-node">
      <xsl:element name="ns-element" namespace="{$target}"/>
  </xsl:variable>

  <xsd:schema>
       <xsl:copy-of
select="saxon:node-set($ns-node)/ns-element/namespace::*[local-name()='']"/>
       <xsl:attribute
name="elementFormDefault">unqualified</xsl:attribute>
       <xsl:attribute
name="attributeFormDefault">unqualified</xsl:attribute>
       <xsl:attribute name="targetNamespace"><xsl:value-of 
select="$target"/></xsl:attribute>
       <xsl:attribute name="version"><xsl:value-of 
select="ACORD-XML-DOC/@version"/></xsl:attribute>

  </xsd:schema>

Does that do what you want?

Alternatively, you could set the value of the targetNamespace
attribute from the xsl:stylesheet declaration by an expression like
   document('')/xsl:stylesheet/namespace::*[local-name()='']
i.e. doing away with the parameter.

Best regards,
Trevor Nash
--
Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271 
email:     tcn(_at_)melvaig(_dot_)co(_dot_)uk

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