Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 22nd, 2008, 05:22 AM
Friend of Wrox
Points: 696, Level: 9
Points: 696, Level: 9 Points: 696, Level: 9 Points: 696, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: Ennis, Clare, Ireland.
Posts: 129
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
Reply With Quote
  #2 (permalink)  
Old May 22nd, 2008, 05:48 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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 -/
Reply With Quote
  #3 (permalink)  
Old May 22nd, 2008, 05:57 AM
mhkay's Avatar
Wrox Author
Points: 18,410, Level: 59
Points: 18,410, Level: 59 Points: 18,410, Level: 59 Points: 18,410, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,949
Thanks: 0
Thanked 289 Times in 284 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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02: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



All times are GMT -4. The time now is 05:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.