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 October 21st, 2010, 07:24 AM
Registered User
 
Join Date: Jun 2010
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Post Namespace question

I fail to understand how the XSLT processor processes my XSLT. Using the following XSLT...

PHP Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output method='xml' />
    <xsl:template match="/">
        <Envelope>
            <soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
                <ns1:SessionHeader soapenv:mustUnderstand="0" xmlns:ns1="urn:enterprise.soap.sforce.com">
                <ns2:sessionId xmlns:ns2="urn:enterprise.soap.sforce.com"><xsl:value-of select="//session/sessionid" /></ns2:sessionId>
                </ns1:SessionHeader>
            </soapenv:Header>
            <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                <logout xmlns="urn:enterprise.soap.sforce.com" />
            </soapenv:Body>
        </Envelope>
    </xsl:template>
</xsl:stylesheet>
... executed on this XML:

PHP Code:
<?xml version="1.0" encoding="UTF-8"?>
<partnersystemtype systypeid="0af004ea-f3a2-4f54-bf28-44407e2c19cc"
    systypename="WS Salesforce PST" systypeversion="12">
    <session>        
             <sessionid>1234</sessionid>
    </session>
</partnersystemtype>
produces the following output:

PHP Code:
<?xml version="1.0" encoding="UTF-8"?>
<Envelope>
    <soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <SessionHeader xmlns:ns1="urn:enterprise.soap.sforce.com"
            soapenv:mustUnderstand="0">
            <sessionId xmlns:ns2="urn:enterprise.soap.sforce.com">1234
            </sessionId>
        </SessionHeader>
    </soapenv:Header>
    <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <logout xmlns="urn:enterprise.soap.sforce.com" />
    </soapenv:Body>
</Envelope>
Ok, but I want to have those namespaces ns1 and ns2 placed where I have placed them in the XSLT (i.e. <ns2:sessionId ... and <ns1:SessionHeader ...). With the current output the target web service cannot find the sessionId node because it seems to be in the wrong namespace (I could be in error about this, though). I probably failed to completely grasp the concept of namespaces. I would be very glad if you can give a short explanation why ns1: and ns2: does not appear in the output.

The output I want to have looks like this:

PHP Code:
<?xml version="1.0" encoding="UTF-8"?>
<Envelope>
    <soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <ns1:SessionHeader xmlns:ns1="urn:enterprise.soap.sforce.com"
            soapenv:mustUnderstand="0">
            <ns2:sessionId xmlns:ns2="urn:enterprise.soap.sforce.com">1234
            </ns2:sessionId>
        </ns1:SessionHeader>
    </soapenv:Header>
    <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <logout xmlns="urn:enterprise.soap.sforce.com" />
    </soapenv:Body>
</Envelope>
Thank you very much

Last edited by Clemensl; October 21st, 2010 at 07:29 AM..
 
Old October 21st, 2010, 08:32 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Which XSLT processor do you use? Have you tried a different processor to check and compare the result?
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 21st, 2010, 08:45 AM
Registered User
 
Join Date: Jun 2010
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Oh sorry, forgot the most important thing.

I am using Saxon 9.

I just tried it with the online xslt processor here: http://www.shell-tools.net/index.php?op=xslt

and it turned out to be ok... I thought it was an issue with the code...

Mmmh... do you know a workaround for saxon?
 
Old October 21st, 2010, 08:55 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I tried your stylesheet (added indent="yes" on xsl: output to be able to read the result) against the input you posted with Saxon 9.2.1.5 HE Java (from the command line) and get the following result:
Code:
<Envelope>
   <soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <ns1:SessionHeader xmlns:ns1="urn:enterprise.soap.sforce.com" soapenv:mustUnderstand="0">
         <ns2:sessionId xmlns:ns2="urn:enterprise.soap.sforce.com">1234</ns2:sessionId>
      </ns1:SessionHeader>
   </soapenv:Header>
   <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <logout xmlns="urn:enterprise.soap.sforce.com"/>
   </soapenv:Body>
</Envelope>
That looks fine to me.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
Clemensl (October 21st, 2010)
 
Old October 21st, 2010, 09:00 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Yeah, same here. Using Saxon 9.1.0.2 Basic from Kernow for Saxon I see what Martin sees.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
Clemensl (October 21st, 2010)
 
Old October 21st, 2010, 09:06 AM
Registered User
 
Join Date: Jun 2010
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Ok, thank you very much

I've updated to saxonb9-1-0-8j and it works now
I should be more confident about my xslt skills

Have a nice day





Similar Threads
Thread Thread Starter Forum Replies Last Post
error CS0234: The type or namespace name 'Xml' does not exist in the namespace 'Syste shailesh_kumar C# 2008 aka C# 3.0 8 August 20th, 2009 03:11 AM
Need to convert an existing namespace and add new namespace to the SOAP xml Prabeen XSLT 10 April 28th, 2009 10:18 AM
copying namespace question JohnBampton XSLT 2 March 30th, 2009 11:52 AM
convert XML to XMl - Another Namespace question bonekrusher XSLT 2 July 10th, 2007 07:32 AM
Question for Chapter2 NameSpace and Fold structure lovehorse BOOK: ASP.NET Website Programming Problem-Design-Solution 1 October 16th, 2006 08:21 AM





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