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 April 10th, 2008, 05:53 PM
Registered User
 
Join Date: Mar 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Namespace problems

Hi all

Have a problem when transforming an XML into another XML

The original (source) xml looks like this:

Code:
<?xml version="1.0" encoding="utf-8"?>
<CancelOrderOut xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.netadmin.se/2006/API_XMLSchema">
  <subscription>
    <subscription_id>133039</subscription_id>
    <subscription_state>
      <state_id>100</state_id>
      <state_name>Disconnected</state_name>
    </subscription_state>
  </subscription>
  <reply>
    <err_number>0</err_number>
    <err_description />
  </reply>
</CancelOrderOut>
while the xsl is as follows:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns="http://www.netadmin.se/2006/API_XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">
<xsl:output method="xml" version="1.0" encoding='UTF-8' indent="yes"/>
<xsl:template match="/">
        <MESSAGE>
            <HEADER>
                <MESSAGE_ID/>
                <REFERENCE_ID></REFERENCE_ID>
                <OPP_REFERENCE_ID></OPP_REFERENCE_ID>
                <MESSAGE_CODE>HK_FROM_NETADMIN</MESSAGE_CODE>
                <VERSION>1</VERSION>
                <CREATION_DATE></CREATION_DATE>
                <SENDER_NAME>NETadmin</SENDER_NAME>
                <RECIPIENT_NAME>Herkules</RECIPIENT_NAME>
            </HEADER>        
            <HK_FROM_NETADMIN>
                <LIST_OF_COMP_PARAMETERS>                
                <xsl:choose>            
                   <xsl:when test="/CancelOrderOut/reply/err_number = 0">
                           <STATUS_CODE>0</STATUS_CODE>
                        <RETURN_CODE>OK</RETURN_CODE>
                   </xsl:when>
                   <xsl:otherwise>
                        <STATUS_CODE><xsl:value-of select="/CancelOrderOut/reply/err_number"/></STATUS_CODE>
                        <RETURN_CODE>ERROR</RETURN_CODE>
                        <STATUS_MSG>NETadmin error. Message from NETadmin adapter.</STATUS_MSG>
                   </xsl:otherwise>
                </xsl:choose>
                </LIST_OF_COMP_PARAMETERS>
            </HK_FROM_NETADMIN>
        </MESSAGE>
    </xsl:template>
</xsl:stylesheet>

The problem is that when using the xmlns in source XML, XPATH doesn't seem to work in XSL, whilst removing the xmlns decl from source XML (and then also in XSL of course), it works fine. I can't find the problem here, the xmlns looks the same in both source xml an xsl 8copied it, actually)

Hope you might see the problem better than me here...

Thanks in advance

/R

 
Old April 10th, 2008, 06:18 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try googling for "XSLT default namespace".

In XSLT 2.0, you can specify xpath-default-namespace in your stylesheet.

In 1.0, any reference in your stylesheet to an element that is in a namespace (which includes a default namespace) must be prefixed, for example match="x:message" or select="x:message/x:body/x:content", where x is declared in the usual way, xmlns:x="your.namespace.uri".

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
namespace Tomi XML 0 September 14th, 2007 04:39 AM
Problems with namespace & classes ayamas Visual Studio 2005 0 October 12th, 2006 08:56 AM
namespace problems in xslt stekker XSLT 2 June 16th, 2006 09:59 AM
Help with Namespace Dwizz VB.NET 2002/2003 Basics 7 April 29th, 2005 07:33 AM





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