Re: [xsl] Generating schema target namespaces from XSLT

Subject: Re: [xsl] Generating schema target namespaces from XSLT
From: Dan Vint <dvint@xxxxxxxxxxxxxx>
Date: Fri, 08 Nov 2002 19:36:50 -0800
I was just now able to give this a try, but unfortunately it doesn't work. I wasn't exactly sure of all the changes that might have been needed so I tried the following for the first solution offered:

1) Created variable and copy-of as shown, no other changes
2) Same as above but removed default namespace declaration from stylesheet element
3) moved copy-of to location after attributes
4) moved copy-of before schema element


Do you have any other suggestions? I didn't try the other solution because I want to pass the namespace value into the stylesheet and not have to edit my stylesheet as this value changes.

This did at least confirm my suspicion that XSLT is missing a good mechanism to manage namespace generation.

..dan

At 08:13 PM 11/2/2002 +0000, Trevor Nash wrote:
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@xxxxxxxxxxxxx


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


Current Thread