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, 2008, 08:22 AM
Registered User
 
Join Date: Mar 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cannot find sub element

Hi

Get an error when trying to transform the xml with xsl. Error saying that <provider_id> (in XSL file) is unexpected, though I removed schema. Any suggestions of what could be wrong?

/R

XML:

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<MESSAGE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <HEADER>
        <MESSAGE_ID>584232</MESSAGE_ID>
        <REFERENCE_ID>139122</REFERENCE_ID>
        <OPP_REFERENCE_ID/>
        <MESSAGE_CODE>HK_TO_NETADMIN</MESSAGE_CODE>
        <VERSION>1</VERSION>
        <CREATION_DATE>2008/01/23 08:03:53</CREATION_DATE>
        <SENDER_NAME>Herkules</SENDER_NAME>
        <RECIPIENT_NAME>WS_NETADMIN</RECIPIENT_NAME>
    </HEADER>
    <HK_TO_NETADMIN>
        <LIST_OF_COMP_PARAMETERS>
            <provider_id>123456789</provider_id>
            <contact_info>
                <contact_info_security_number>670703-7875</contact_info_security_number>
            </contact_info>
        </LIST_OF_COMP_PARAMETERS>
        <REQUESTED_OPERATION>GetCustomers</REQUESTED_OPERATION>
    </HK_TO_NETADMIN>
</MESSAGE>

XSL:

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/">
        <GetCustomersIn xmlns="http://www.netadmin.se/2006/API_XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <xsl:apply-templates select="LIST_OF_COMP_PARAMETERS">
                <provider_id><xsl:value-of select="provider_id"/></provider_id>
                <search_arguments>
                    <contact_info>
                        <xsl:if test="string(contact_info_security_number)">
                            <security_number><xsl:value-of select="contact_info_security_number"/></security_number>            
                        </xsl:if>
                    </contact_info>
                </search_arguments>
            </xsl:apply-templates>
        </GetCustomersIn>
    </xsl:template>

</xsl:stylesheet>
 
Old March 17th, 2008, 08:33 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

That stylesheet is not correct, the xsl:apply-templates cannot have any contents besides xsl:sort and/or xsl:with-param.
Here is a corrected stylesheet, though I am mainly guessing what you want to achieve:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.netadmin.se/2006/API_XMLSchema" >
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
        <GetCustomersIn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <xsl:apply-templates select="MESSAGE/HK_TO_NETADMIN/LIST_OF_COMP_PARAMETERS">

            </xsl:apply-templates>
        </GetCustomersIn>
    </xsl:template>


    <xsl:template match="LIST_OF_COMP_PARAMETERS">
                <provider_id><xsl:value-of select="provider_id"/></provider_id>
                <search_arguments>
                    <contact_info>
                        <xsl:if test="contact_info/contact_info_security_number">
                            <security_number><xsl:value-of select="contact_info/contact_info_security_number"/></security_number>            
                        </xsl:if>
                    </contact_info>
                </search_arguments>
    </xsl:template>
</xsl:stylesheet>

 
Old March 17th, 2008, 08:47 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The only elements allowed inside xsl:apply-templates are xsl:sort and xsl:with-param. I can't correct your code for you because I've no idea what you intended it to mean.

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
How to find no.of childnodes of a tag element? sachin635 .NET Framework 3.5 0 September 15th, 2008 04:32 AM
Problem adding element to the previous element dani1 XSLT 5 September 10th, 2008 01:38 AM
translate element name to element name lexzeus XSLT 3 September 4th, 2006 09:04 AM
Open Word Doc from Access - find, find next save donaldmaloney Access VBA 1 May 25th, 2005 11:09 AM
adding of element and assigning to one element sushovandatta XSLT 2 November 16th, 2004 07:04 PM





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