xsl-list
[Top] [All Lists]

RE: [xsl] Namespaces.

2006-03-30 04:34:15

Now, I want to copy customRows into supplier. I created the following 
code to do this:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:sup="http://www.calypso.net.au/apps/supub/SupplierV1.0";>
  <xsl:template match="files">
     <xsl:apply-templates select="sup:supplier"/>
  </xsl:template> 

  <xsl:template match="sup:supplier">
    <supplier>
      <xsl:apply-templates select="@*|node()"/>
      <supplementary>
      <xsl:apply-templates select="../customRows"/>
      </supplementary>
    </supplier>
  </xsl:template>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

Works fine, except it copies namespace information to children nodes 
that doesn't seem to exists. eg:

<supplier 
xmlns:sup="http://www.calypso.net.au/apps/supub/SupplierV1.0";>

This namespace is being added because of the rule that literal result
elements copy all the in-scope namespaces from the stylesheet. You can
prevent this using exclude-result-prefixes="sup" on the xsl:stylesheet
element.

    <priority 
xmlns="http://www.calypso.net.au/apps/supub/SupplierV1.0"; 
xmlns:dir="http://apache.org/cocoon/directory/2.0"; 
xmlns:cinclude="http://apache.org/cocoon/include/1.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>1</priority>


I have checked, these elements are not in the source document, and it 
only seems to affect the children of supplier. 

You haven't shown the source document but I strongly suspect that priority
is an element in the source document and that these are its in-scope
namespaces.

In XSLT 2.0 you can copy an element without copying its in-scope namespaces
using <xsl:copy copy-namespaces="no">. In 1.0, you can't: you have to
reconstruct the element using <xsl:element>.

Michael Kay
http://www.saxonica.com/



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>