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 February 15th, 2013, 02:01 AM
Registered User
 
Join Date: Feb 2013
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stylesheet not returning child elements

Hello,

I'm new to XSLT and I am wondering why this style sheet is not returning any child elements, it only brings back the root element.

Thanks.

Regards,
Jorbri1513


Code:
<?xml version="1.0" encoding="UTF-8"?>
   <xsl:stylesheet version="2.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:wd="urn:com.workday/bsvc" wd:version="v17"> 
        <xsl:strip-space elements="*"/>
        <xsl:output indent="yes" method="text"/>
        <xsl:template match="/Get_Worker_Response"> 
        
         <xsl:for-each select="wd:Response_Data/wd:Worker/wd:Worker_Data">
                <xsl:value-of select="wd:Worker_ID"/>
       </xsl:for-each>     
   </xsl:template>  
</xsl:stylesheet>
 
Old February 15th, 2013, 03:04 AM
Registered User
 
Join Date: Feb 2013
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Here is an xml snippett

Code:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
   <env:Body>
      <wd:Get_Workers_Response wd:version="v17" xmlns:wd="urn:com.workday/bsvc">
         <wd:Request_Criteria>
            <wd:Organization_Reference wd:Descriptor="MMM Money Market Mansion (Marcia Menos)">
               <wd:ID wd:type="WID">f10da305867044b8a30c67671e4034c1</wd:ID>
               <wd:ID wd:type="Organization_Reference_ID">SUPERVISORY_ORGANIZATION-1-219</wd:ID>
            </wd:Organization_Reference>
         </wd:Request_Criteria>
         <wd:Response_Results>
            <wd:Total_Results>5</wd:Total_Results>
            <wd:Total_Pages>1</wd:Total_Pages>
            <wd:Page_Results>5</wd:Page_Results>
            <wd:Page>1</wd:Page>
         </wd:Response_Results>
         <wd:Response_Data>
            <wd:Worker>
               <wd:Worker_Reference wd:Descriptor="Gabriel Bezerra">
                  <wd:ID wd:type="WID">1efbe4be1e764a4d8dd205ee6550cafb</wd:ID>
                  <wd:ID wd:type="Employee_ID">21305</wd:ID>
               </wd:Worker_Reference>
               <wd:Worker_Data>
                  <wd:Worker_ID>21305</wd:Worker_ID>
                  <wd:User_ID>gbezerra</wd:User_ID>
                  <wd:Personal_Data>
                     <wd:Name_Data>
                        <wd:Legal_Name_Data>
                           <wd:Name_Detail_Data wd:Formatted_Name="Gabriel Bezerra" wd:Reporting_Name="Bezerra, Gabriel">
                              <wd:Country_Reference wd:Descriptor="Brazil">
                                 <wd:ID wd:type="WID">1a29bb1357b240ab99a2fa755cc87c0e</wd:ID>
                                 <wd:ID wd:type="ISO_3166-1_Alpha-2_Code">BR</wd:ID>
                                 <wd:ID wd:type="ISO_3166-1_Alpha-3_Code">BRA</wd:ID>
                                 <wd:ID wd:type="ISO_3166-1_Numeric-3_Code">76</wd:ID>
                              </wd:Country_Reference>
                              <wd:First_Name>Gabriel</wd:First_Name>
                              <wd:Last_Name>Bezerra</wd:Last_Name>
                           </wd:Name_Detail_Data>
                        </wd:Legal_Name_Data>
                        <wd:Preferred_Name_Data>
                           <wd:Name_Detail_Data wd:Formatted_Name="Gabriel Bezerra" wd:Reporting_Name="Bezerra, Gabriel">
                              <wd:Country_Reference wd:Descriptor="Brazil">
                                 <wd:ID wd:type="WID">1a29bb1357b240ab99a2fa755cc87c0e</wd:ID>
                                 <wd:ID wd:type="ISO_3166-1_Alpha-2_Code">BR</wd:ID>
                                 <wd:ID wd:type="ISO_3166-1_Alpha-3_Code">BRA</wd:ID>
                                 <wd:ID wd:type="ISO_3166-1_Numeric-3_Code">76</wd:ID>
                              </wd:Country_Reference>
                              <wd:First_Name>Gabriel</wd:First_Name>
                              <wd:Last_Name>Bezerra</wd:Last_Name>
                           </wd:Name_Detail_Data>
                        </wd:Preferred_Name_Data>
                     </wd:Name_Data>
                     <wd:Gender_Reference wd:Descriptor="Male">
                        <wd:ID wd:type="WID">d3afbf8074e549ffb070962128e1105a</wd:ID>
                        <wd:ID wd:type="Gender_Code">Male</wd:ID>
 
Old February 15th, 2013, 05:06 AM
Authorized User
 
Join Date: Feb 2013
Posts: 19
Thanks: 2
Thanked 0 Times in 0 Posts
Default

If you want to copy everything under the declared root.

<xsl:templatematch="*"> <!-- * being root -->
<xsl:copy>
<xsl:copy-of select="@*">
<xsl:apply-temples/>
</xsl:copy>
</xsl:template>

Change * to your "root" folders or leave as * and it will copy Everything.
 
Old February 15th, 2013, 05:11 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

  1. Get_Workers_Response is not the same as Get_Worker_Response
  2. Get_Workers_Response is in namespace so needs wd: prefix in match attribute
  3. Need to use //wd:Get_Workers_Response or full path after declaring env namespace prefix: /env:Envelope/env:Body/wd:Get_Workers_Response or simply wd:Get_Workers_Response on match attribute as element is not immediately under root
__________________
Joe
http://joe.fawcett.name/

Last edited by joefawcett; February 15th, 2013 at 05:13 AM..
 
Old February 15th, 2013, 05:59 AM
Registered User
 
Join Date: Feb 2013
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Worked like a charm

Joe,

Thanks. I corrected the Get_Worker_Response to Get_Workers_Response and included the env name space and it worked like a charm.

Thanks again Joe, "You Are The Man".

Regards,
Jorbri1513

Code:
<?xml version="1.0" encoding="UTF-8"?>
   <xsl:stylesheet version="2.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
       xmlns:wd="urn:com.workday/bsvc" wd:version="v17"> 
        <xsl:strip-space elements="*"/>
        <xsl:output indent="yes" method="text"/>
        <xsl:template match="wd:Get_Workers_Response"> 
                
         <xsl:for-each select="wd:Response_Data/wd:Worker/wd:Worker_Data">
                <xsl:value-of select="wd:Worker_ID"/>
       </xsl:for-each>     
   </xsl:template>  
</xsl:stylesheet>





Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath to exclude child elements. WilliamYou XSLT 2 December 18th, 2012 12:58 PM
copy-of select= not returning all elements jay_c XSLT 8 August 8th, 2009 01:38 PM
Returning elements. Neal XSLT 2 May 13th, 2007 04:38 PM
Checking for valid child elements. Chamkaur XSLT 0 January 25th, 2007 06:51 PM
Child package returning failure vipulcs SQL Server DTS 6 January 10th, 2005 12:26 AM





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