"Don" <do*************@hotmail.com> wrote in message news:uy**************@TK2MSFTNGP10.phx.gbl...
I forgot to include the xsl template that is performing the transform.
That addition definitely clears matters up. :-)
I guess I just need some code to ignore or handle the namespace
reference at the root of the document. If I need to do something
different, let me know.
Two very simple changes: add an xmlns declaration to the <xsl:stylesheet>
element of your primary XSLT transform that associates some prefix
with the namespace URI:
http://tempuri.org/formgenerator.xsd.
Then, use this prefix for all elements in the template's XPath expressions
(it's not normally necessary to prefix the attributes, because attributes by
default will be unqualified, unless you're using an XML schema with an
attributeForm='qualified' on an <xsd:attribute> or attributeFormDefault=
'qualified' on the <xsd:schema>).
An optional third step is to use <xsl:element> for <form>, <link> and
<script> tags, otherwise you may get the XML namespace declaration
repeatedly showing up. I demonstrate this here.
Here's the fixed-up template (and xmlns on the <xsl:stylesheet>).
- - - nsAwareTransform.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://tempuri.org/formgenerator.xsd" >
<!--
. . .
-->
<xsl:template match="/">
<xsl:element name="xsl:stylesheet">
<xsl:attribute name="version">1.0</xsl:attribute>
<xsl:element name="xsl:template">
<xsl:attribute name="name">
<xsl:value-of select="/ns:WEBFORM/@templatename"/>
</xsl:attribute>
<xsl:if test="/ns:WEBFORM/@CSS='1'">
<xsl:value-of disable-output-escaping="yes"
select="/ns:WEBFORM/ns:CSSREF" />
<!-- <link rel="stylesheet" type="text/css" href="/CSS/corporate.css" /> -->
<xsl:element name="link">
<xsl:attribute name="rel">stylesheet</xsl:attribute>
<xsl:attribute name="type">text/css</xsl:attribute>
<xsl:attribute name="href">/CSS/corporate.css</xsl:attribute>
</xsl:element>
</xsl:if>
<xsl:if test="/ns:WEBFORM/@JS='1'">
<!-- <script type="text/javascript" src="/include/helper.js"></script> -->
<xsl:element name="script">
<xsl:attribute name="type">text/javascript</xsl:attribute>
<xsl:attribute name="src">/include/helper.js</xsl:attribute>
<xsl:value-of disable-output-escaping="yes"
select="/ns:WEBFORM/ns:JS" />
</xsl:element>
</xsl:if>
<xsl:choose>
<xsl:when test="/ns:WEBFORM/@NOFORMTAG='1'">
<xsl:apply-templates />
</xsl:when>
<xsl:otherwise>
<xsl:element name="form">
<xsl:if test="/ns:WEBFORM/@ONSUBMIT">
<xsl:attribute name="onsubmit">
<xsl:value-of
select="/ns:WEBFORM/@ONSUBMIT"/>
</xsl:attribute>
</xsl:if>
<xsl:attribute name="method">
<xsl:value-of
select="/ns:WEBFORM/@method"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of
select="/ns:WEBFORM/@name" />
</xsl:attribute>
<xsl:attribute name="action">
<xsl:value-of select="/ns:WEBFORM/@action" />
</xsl:attribute>
<xsl:apply-templates />
</xsl:element> <!-- end form -->
</xsl:otherwise>
</xsl:choose>
</xsl:element> <!-- end xsl:template -->
</xsl:element> <!-- end xsl:stylesheet -->
</xsl:template>
<!--
.. . .
-->
</xsl:stylesheet>
- - -
Notice how the ns namespace prefix is declared in the xsl:stylesheet
of this stylesheet, and then used as the prefix locating the elements in
your source XML document. This is what makes the stylesheet NS
aware.
When I added 3 attributes to your original example XML's WEBFORM
element (CSS="1", JS="1" and NOFORMTAG="1"), I was then able
to produce the same XSLT as you indicated in your correct example
using this stylesheet and Saxon.
If you have any other questions about how this works, just ask. :-)
Derek Harmon