Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 4th, 2009, 07:27 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default Outputting a Namespace as an attribute

Hi,

I'm using version 1.0 and Altova XMLSpy for validation.

When attempting to output the following code, I recieve the 'Undefined Namespace Prefix' message (i.e. 'xmlns:' in the first attribute output format).

Code:
 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:md="http://schemas.microsoft.com/dynamics/2006/02/documents/VCTMovementDelivery" xmlns:js-function="//CALjs-functions">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" />
 
<xsl:variable name="strDestEndPnt" select="./Envelope/Header/DestinationEndPoint"/>
 
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
 
<xsl:template match="/"> 
<xsl:call-template name="F4FDelvyNotif"/> 
<!--<xsl:call-template name="copy"/>-->
</xsl:template>
 
 
<xsl:template name="F4FDelvyNotif">
<xsl:element name="F4FDeliveryNotification">
<xsl:attribute name="xmlns:xsi">http://www.w3.org/2001/XMLSchema-instance</xsl:attribute>
<xsl:attribute name="xsi:noNamespaceSchemaLocation">http://www.first4farming.com/F4FXML/Schemas/v3_0_3/F4FDel.xsd</xsl:attribute>
<xsl:attribute name="DeliveryNotificationType">
<xsl:choose>
<xsl:when test="$strDestEndPnt='F4FGRNMovementDeliveryNote'">
<xsl:text>Goods Received Note</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute> 
<xsl:attribute name="DocumentType">
<xsl:choose>
<xsl:when test="$strDocPurpose='Original'">
<xsl:text>New</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute> 
<xsl:call-template name="DocHdr"/>
<xsl:call-template name="DlyNotHdr"/>
<xsl:call-template name="TrnsDtls"/>
<xsl:call-template name="DlyLine"/>
<xsl:call-template name="DlyCtrlTtls"/>
</xsl:element>
</xsl:template>
 
</xsl:stylesheet>
Can this be overcome within a single XSLT sheet (without hard-coding each element)? Or do I need some other external work-around?

I'm uncertain as to whether this is permitted by W3 conventions.

I'm also contacting XMLSpy to see if this is a limitation within their product.

Can anyone help?

Thanks in advance,
__________________
Neal

A Northern Soul
 
Old March 4th, 2009, 08:28 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

In the XSLT/XPath data model namespace declarations are not attributes, rather they are represented by namespace nodes.
When you create result elements or attributes you do not need to create any namespace declarations, rather you need to create the elements or attributes in the proper namespace and then the serializer will add any namespace declarations as needed.

So instead of
Code:
<xsl:template name="F4FDelvyNotif">
<xsl:element name="F4FDeliveryNotification">
<xsl:attribute name="xmlns:xsi">http://www.w3.org/2001/XMLSchema-instance</xsl:attribute>
<xsl:attribute name="xsi:noNamespaceSchemaLocation">http://www.first4farming.com/F4FXML/Schemas/v3_0_3/F4FDel.xsd</xsl:attribute>
you only need
Code:
<xsl:template name="F4FDelvyNotif">
     <xsl:element name="F4FDeliveryNotification">
          <xsl:attribute name="xsi:noNamespaceSchemaLocation" namespace="http://www.w3.org/2001/XMLSchema-instance">http://www.first4farming.com/F4FXML/Schemas/v3_0_3/F4FDel.xsd</xsl:attribute>
although I would use literal result elements instead to shorten the code:
Code:
<xsl:template match="F4FDelvyNotif">
  <F4FDeliveryNotification xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://www.first4farming.com/F4FXML/Schemas/v3_0_3/F4FDel.xsd">
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog

Last edited by Martin Honnen; March 4th, 2009 at 08:28 AM.. Reason: fixing code sample
The Following User Says Thank You to Martin Honnen For This Useful Post:
Neal (March 4th, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Not outputting a specific node zach_1988 XSLT 3 December 2nd, 2008 10:49 AM
Outputting Array manih C++ Programming 2 June 14th, 2006 08:24 PM
Outputting table permissions crisan Access 1 May 25th, 2005 06:39 AM
attribute namespace prefix tsmith XSLT 1 August 12th, 2004 06:01 AM
Outputting an end of line y_simonson XSLT 1 February 5th, 2004 05:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.