Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
| 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
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 1st, 2006, 09:06 AM
Registered User
Join Date: Jun 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using result of one template in another

Hi there,

I am new to XSLT and need some help with my translation. I have an XML doc that needs to have its element names changed and then re-structured based on come criteria. The criteria is category names. I need to create new elements that group elements based on common categories. Here is my XSLT doc:

<xsl:stylesheet version="2.0"



            <xsl:import href="copy.xslt"/>

            <xsl:variable name="cat" select="/*/*/@cat[not(. = ../preceding-sibling::*/@cat)]"/>

            <xsl:variable name="mapping-rules" select="document('UoPToELSMapping.xslt')"/>

            <xsl:variable name="lookup" select="$mapping-rules/*[els:*]"/>

            <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

            <xsl:template match="/">

                        <xsl:apply-templates mode="sub"/>

                         <xsl:apply-templates mode="grouper"/>


            <xsl:template match="*" mode="sub">


                                    <xsl:when test="$lookup/els:element[@from=name(current())]">

                                                <xsl:element name="{$lookup/els:element[@from=name(current())]/@to}">

                                                            <xsl:attribute name="cat">

                                                                        <xsl:value-of select="$lookup/els:element[@from=name(current())]/@cat"/>


                                                            <xsl:attribute name="ids">

                                                                        <xsl:value-of select="$lookup/els:element[@from=name(current())]/@ids"/>


                                                            <xsl:apply-templates select="@*"/>









            <xsl:template match="*" mode="grouper">

            <xsl:for-each select="$cat">

                        <xsl:variable name="cat-name" select="."/>

                                    <xsl:element name="{$cat-name}">

                                    <xsl:for-each select="/*/*[@cat=$cat-name]">


                                                                        <xsl:apply-templates select="."/>







And my mapper is:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"



<els:element from="Person_Names_First_Name" to="FIRST_NAME" cat="LEAD_TRANS_DETAILS"/>

<els:element from="Person_Names_Last_Name" to="LAST_NAME" cat="LEAD_TRANS_DETAILS"/>

<els:element from="Address_Home_Street" to="STREET1" cat="LEAD_ADDRESS" type="Home" ids="1"/>

<els:element from="Address_Home_Line2" to="STREET2" cat="LEAD_ADDRESS" type="Home" ids="1"/>

<els:element from="Address_Home_City" to="CITY" cat="LEAD_ADDRESS" type="Home" ids="1"/>

<els:element from="Address_Home_State_Prov" to="STATE" cat="LEAD_ADDRESS" type="Home" ids="1"/>

<els:element from="Address_Home_Country" to="COUNTRY" cat="LEAD_ADDRESS" type="Home" ids="1"/>

<els:element from="Address_Home_Postal_Code" to="ZIP" cat="LEAD_ADDRESS" type="Home" ids="1"/>

<els:element from="Address_Business_Street" to="STREET1" cat="LEAD_ADDRESS" type="Business" ids="2"/>

<els:element from="Address_Business_Line2" to="STREET2" cat="LEAD_ADDRESS" type="Business" ids="2"/>

<els:element from="Address_Business_City" to="CITY" cat="LEAD_ADDRESS" type="Business" ids="2"/>

<els:element from="Address_Business_State_Prov" to="STATE" cat="LEAD_ADDRESS" type="Business" ids="2"/>

<els:element from="Address_Business_Country" to="COUNTRY" cat="LEAD_ADDRESS" type="Business" ids="2"/>

<els:element from="Address_Business_Postal_Code" to="ZIP" cat="LEAD_ADDRESS" type="Business" ids="2"/>

<els:element from="Phone_Home_Country" to="Phone_Home_Country" cat="LEAD_PHONE" type="Home" ids="3"/>

<els:element from="Phone_Home_Area" to="Phone_Home_Area" cat="LEAD_PHONE" type="Home" ids="3"/>

<els:element from="Phone_Home_Number" to="PHONE_NUMBER" cat="LEAD_PHONE" type="Home" ids="3"/>

<els:element from="Phone_Business_Country" to="Phone_Business_Country" cat="LEAD_PHONE" type="Business" ids="4"/>

<els:element from="Phone_Business_Area" to="Phone_Business_Area" cat="LEAD_PHONE" type="Business" ids="4"/>

<els:element from="Phone_Business_Number" to="PHONE_NUMBER" cat="LEAD_PHONE" type="Business" ids="4"/>

<els:element from="Phone_Business_Extension" to="Phone_Business_Extension" cat="LEAD_PHONE" type="Business" ids="4"/>

<els:element from="Email_Address_Home_Email" to="LEAD_EMAIL_ADDRESS" cat="LEAD_EMAIL" type="Home" ids="5"/>

<els:element from="Email_Address_Business_Email" to="LEAD_EMAIL_ADDRESS" cat="LEAD_EMAIL" type="Business" ids="6"/>

<els:element from="Std_Primary_Lead_Source" to="Std_Primary_Lead_Source" cat="LEAD_INFO_DETAIL"/>

<els:element from="Create_Date" to="Create_Date" cat="LEAD_INFO_DETAIL"/>

<els:element from="Actual_Program" to="Actual_Program" cat="LEAD_INFO_DETAIL"/>

<els:element from="Program_of_Interest" to="Program_of_Interest" cat="LEAD_INFO_DETAIL"/>

<els:element from="Enrollment_Status" to="Enrollment_Status" cat="LEAD_INFO_DETAIL"/>

<els:element from="Std_Orga_Number" to="Std_Orga_Number" cat="LEAD_INFO_DETAIL"/>

<els:element from="Site_ids" to="Site_ids" cat="LEAD_INFO_DETAIL"/>


However, I do not get the desired effect. I can successfully substitute the element names, but grouping part never behaves the way that I need it.

I appreciate any help that you can provide.



Reply With Quote
  #2 (permalink)  
Old June 4th, 2006, 04:56 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

First, I'm not sure why you've made the mapping file be a stylesheet module. Why not make it an ordinary XML document?

Second, I guess from the title of your post that when you write:

<xsl:template match="/">

                        <xsl:apply-templates mode="sub"/>

                         <xsl:apply-templates mode="grouper"/>


you are hoping that the "grouper" template will be applied to the result of the "sub" template. The standard pattern for this in XSLT 2.0 is:

<xsl:variable name="temp">
  <xsl:apply-templates mode="sub"/>
<xsl:apply-templates select="$temp" mode="grouper"/>

In 1.0 this requires the xx:node-set() function which most XSLT processors offer as a vendor extension:

<xsl:variable name="temp">
  <xsl:apply-templates mode="sub"/>
<xsl:apply-templates select="xx:node-set($temp)" mode="grouper"/>

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
GridView and SQL More than one result = one result DarkForce ASP.NET 2.0 Basics 0 July 20th, 2007 04:29 AM
xsl template, next result or next 10 results ge_or_gi XSLT 8 April 2nd, 2007 07:01 AM
how to use call-template result in a test? briforge XSLT 6 February 13th, 2006 06:54 PM
calling one template in other template VijayKumar XSLT 3 September 15th, 2005 11:12 AM
How many Result? Mantis PHP Databases 1 April 15th, 2005 03:37 PM

All times are GMT -4. The time now is 08:17 PM.

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