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 May 22nd, 2008, 05:22 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default Processing MS Dynamics XML Envelope

Hi,

I have used XSLT on-and-off for a few months and have made reasonable progress. However......, a new requirement within our business has meant that we now need to:[*]Use XSLT on 'Envelope' XML[*]Output in 'Text' format (Previously we have only used XML output)

These are files from the Microsoft Dynamics environment.

I use XMLSpy Version 5 Release 3 to test and debug and have found that apart from simple root extract statments (i.e. '.'), the varibles I set for the 'Enveloped' XML are NOT being populated/identified.

The XML version is 1.0

The following XML is an abbreviated sample of a larger file:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2006/02/documents/Message">
    <Header>
        <MessageId>{4C139}</MessageId>
        <SourceEndpointUser/>
        <SourceEndpoint>kwt</SourceEndpoint>
        <DestinationEndpoint>WeighbridgeSite</DestinationEndpoint>
        <Action>ListMovementDelivery</Action>
        <RequestMessageId/>
    </Header>
    <Body>
        <MovementDelivery xmlns="http://schemas.microsoft.com/dynamics/2006/02/documents/MovementDelivery">
            <DocPurpose>Original</DocPurpose>
            <SenderId>kwt</SenderId>
            <VCTMovements class="entity">
                <DlvMode>Road</DlvMode>
                <HasClaim>No</HasClaim>
                <RecId>4737150574</RecId>
                <RecVersion>1</RecVersion>
            </VCTMovements>
        </MovementDelivery>
    </Body>
</Envelope>
The XSLT that I have started (I realise that it is in very simple form at the moment - but it is at a TEST stage) is:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://schemas.microsoft.com/dynamics/2006/02/documents/Message">
<xsl:output method="text" />
<xsl:template match="/">
    <xsl:apply-templates select="Envelope/Header" />
</xsl:template>

<xsl:variable name="FindIt" select="/Body/MovementDelivery/SenderId"/>
<xsl:variable name="FindIt2" select="//Body/MovementDelivery/DocPurpose"/>

<xsl:template match="Header">
    <xsl:value-of select="./SourceEndpoint"/>
</xsl:template>
</xsl:stylesheet>

The output file just reads the whole file:

[code<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://schemas.microsoft.com/dynamics/2006/02/documents/Message" version="1.0"><xsl:output method="xml"/><xsl:template match="/"><xsl:apply-templates select="Envelope/Header"/></xsl:template><xsl:variable name="Entcnt" select="count(//Body/VCTMovements[@Class='Entity'])"/><xsl:variable name="FindIt" select="//Body/MovementDelivery/SenderId"/><xsl:variable name="FindIt2" select="//Body/SenderId"/><xsl:template match="Header"><xsl:value-of select="SourceEndpoint"/></xsl:template></xsl:stylesheet>[/code]

It's probably a very simple explanation, but it's got me.
Has it got something to do with the namespace/schemas? We previously used 'http://www.w3.org/1999/XSL/Transform' to interpret the code, but if I use it in the context of this file, the output file is blank.

Thanks in advance,

Neal








Neal

A Northern Soul
__________________
Neal

A Northern Soul
 
Old May 22nd, 2008, 05:48 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You can't just 'redefine' the xsl prefix like that!

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ENV="http://schemas.microsoft.com/dynamics/2006/02/documents/Message">
<xsl:output method="text" />
<xsl:template match="/">
    <xsl:apply-templates select="ENV:Envelope/ENV:Header" />
</xsl:template>

<xsl:variable name="FindIt" select="/ENV:Body/ENV:MovementDelivery/ENV:SenderId"/>
<xsl:variable name="FindIt2" select="//ENV:Body/ENV:MovementDelivery/ENV:DocPurpose"/>

  <xsl:template match="ENV:Header">    
    <xsl:value-of select="./ENV:SourceEndpoint"/>    
  </xsl:template>
</xsl:stylesheet>
/- Sam Judson : Wrox Technical Editor -/
 
Old May 22nd, 2008, 05:57 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Firstly, the namespace must be 'http://www.w3.org/1999/XSL/Transform' otherwise this is not an XSLT stylesheet at all.

Take a look at the first sticky post in this forum concerning the default namespace. You need to declare

xmlns:m="http://schemas.microsoft.com/dynamics/2006/02/documents/Message"

and then use path expressions (and match patterns) like m:Envelope/m:Header. (And similarly for the MovementDelivery namespace).

Also note: /Body/MovementDelivery/SenderId won't find anything because Body isn't the outermost element.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Processing ENTITY and NOTATION lines in xml mrame XSLT 2 August 1st, 2008 01:24 PM
C#, Sharepoint, BDC, Dynamics GP10, Webparts NeilSc .NET Web Services 1 January 20th, 2008 03:34 PM
Need help on Processing two xml and updating one a sayanand XSLT 7 October 12th, 2007 05:35 AM
Fluid Dynamics with WPF : Error bhavsac Windows Presentation Foundation 0 July 17th, 2007 07:21 AM
Controlling Outgoing Custom XML Envelope Content RaminS Biztalk 1 June 12th, 2003 06:03 AM





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