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 17th, 2009, 07:36 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default Using non-literals in literal element structure

xml version="1.0"

Hi,

When saving the xslt file (below), it appeared easier to code using literal result elements rather than the xsl:element approach.

I found this was perhaps due to the inclusion of:
'xsi:noNamespaceSchemaLocation'
(http://first4farming.com/F4FXML/Schemas/v3_0_2/F4FInv.xsd)
My problem is that once the root element 'F4FInvoice' is selected, I can't call a further template or add a non-literal element without producing an error (i.e.
  • Mandatory Element is expected
or
  • Only text allowed inside [Element Name])
Code:
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msg="http://schemas.microsoft.com/dynamics/2006/02/documents/Message" xmlns:si="http://schemas.microsoft.com/dynamics/2006/02/documents/SalesInvoice" xmlns:xsi="http://first4farming.com/F4FXML/Schemas/v3_0_2/F4FInv.xsd" xmlns:js-function="//CALjs-functions">

<!-- Import the CAL js-functions template -->
<xsl:import href="CALjs-functions.xslt"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" />
<xsl:variable name="DteTmeNow" select="js-function:DateTimeNow()"/>
<xsl:variable name="strAction" select="./msg:Envelope/msg:Header/msg:Action"/>
<xsl:variable name="strDestEndPnt" select="./msg:Envelope/msg:Header/msg:DestinationEndpoint"/>
<xsl:variable name="strDocPurpose" select="./msg:Envelope/msg:Body/si:SalesInvoice/si:DocPurpose"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="/">
<xsl:choose>
<!--In the specification-->
<xsl:when test="$strDestEndPnt='F4F_S1_SendSalesInvoice' and $strAction='readSalesInvoice' and $strDocPurpose='Original">
<xsl:call-template name="F4FInv1"/>
</xsl:when>

<xsl:otherwise>
<xsl:call-template name="F4FInv7"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="F4FInv1">
<F4FInvoice xsi:noNamespaceSchemaLocation="http://first4farming.com/F4FXML/Schemas/v3_0_2/F4FInv.xsd" InvoiceType="Invoice" DocumentType="New" TypeOfSupply="Sale" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<F4FDocumentHeader>
<SchemaVersion>3</SchemaVersion>
<SchemaStatus>Approved</SchemaStatus>
<DocumentCreated DateTimeType="Document Created">
<!--<xsl:value-of select="js-function:DateTimeNow()"/>-->
<xsl:text>20090216 10:00</xsl:text>
</DocumentCreated>
</F4FDocumentHeader>
<xsl:call-template name="DocHdr"/>
<xsl:call-template name="InvHdr"/>
<xsl:call-template name="TrnsDtls"/>
<xsl:call-template name="InvLine"/>
<xsl:call-template name="TaxTrail"/>
<xsl:call-template name="InvCtrlTtls"/>
</F4FInvoice>
</xsl:template>
</xsl:stylesheet>
Is there a method to by-pass this, so I can execute the non-literals

<xsl:text>20090216 10:00</xsl:text>
or
<xsl:call-template name="DocHdr"/>

Thanks in advance,

__________________
Neal

A Northern Soul
 
Old March 17th, 2009, 07:48 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You don't make it clear whether this error is occurring in your XML/XSLT editor or when you compile the stylesheet.

Anyway, some tools attach unreasonable significance to the presence of an xsi:schemaLocation attribute, and treat it as a license to perform schema validation, which you don't want to happen here. You could of course switch to generating this attribute using xsl:attribute, or if you prefer you could use <xsl:namespace-alias> to set an alias for the xsi namespace, so that the namespace used in the stylesheet is different from the "real" xsi namespace.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Label vs Literal pinch BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 October 9th, 2007 01:01 PM
What's the use of braces in a string literal? aaaa0441 Pro PHP 7 January 20th, 2007 04:23 AM
Literal Control bilal589 ASP.NET 1.0 and 1.1 Basics 5 August 19th, 2006 01:42 PM
Using right() to return a literal value Somed00d Access 4 February 8th, 2006 02:56 PM
literal result element <head> pietdemeester BOOK: XSLT Programmer's Reference, 2nd Edition 0 June 21st, 2003 08:13 PM





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