Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 10th, 2005, 10:21 PM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default xsl:copy copies everywhere

I am trying to take a submitted xml find if it has some values in it and if so, add them in that submitted xml at a specific location. For the example given below, if I find Transform/DataStore in the xml I need to add elements
<resource>
<name>DATASTORE</name>
</resource>
inside the <SchedulerInformation> tag. In the case that SchedulerInformation having a space or some other elements inside, it works correctly. But, in the case given below where SchedulerInformation tag is empty, the xslt is placing the resource names everywhere in the XML. Please help me with this problem. Thanks a Lot.


The XML:
**********************************************
<?xml version="1.0" encoding="ISO-8859-1"?>
<Job id="WFG" submitType="publishAndSubmit" submitRun="true">
    <Engine configurationFile="GENERATE_CONFIG_FILE">
        <Parameter id="Env">/mnt/wfg_2.1/etc/US_WFG_Dev.env</Parameter>
        <Parameter id="SEQ">No</Parameter>
        <Parameter id="DOMAIN"/>
        <Parameter id="LINK_TYPE"/>
    </Engine>
    <Queue id="cii" emailAddress="*******">
        <Billing id="billing_standard">
            <Parameter id="LIN">202142</Parameter>
            <Parameter id="PRO">2VY06</Parameter>
            <Parameter id="FIL">203</Parameter>
            <Parameter id="GL">12380</Parameter>
            <Parameter id="BU">ESI</Parameter>
        </Billing>
    <EventDrivenSubmission>
<SchedulerInformation id="f3c61afa-bbd6-1004-8f0f-78ded200a8e7"/>
            <NotificationList>
                <Notification>
                    <JobEvent id="Job Submitted"/>
                    <JobEvent id="Job Initiated"/>
                    <JobEvent id="Job Queued"/>
                    <JobEvent id="Job Started"/>
                    <JobEvent id="Job Ended"/>
                    <JobEvent id="Job Cancelled"/>
                    <JobEvent id="Job Held"/>
                </Notification>
            </NotificationList>
        </EventDrivenSubmission>
    </Queue>
    <Transform>
        <DataStore name="/mnt/datagrid1/DEFT/" location="ftpsharedev">
            <RecordLayout>
                <Field fieldDelimiter="none"/>
            </RecordLayout>
        </DataStore>
    </Transform>
</Job>
**********************************************

The XSL:
**********************************************
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

       <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes" />


    <xsl:variable name="mount" select="'/mnt/datagrid'"/>
    <xsl:variable name="dataval" select="'DATAGRID'"/>


<xsl:template match="/ | @* | node()">
    <xsl:copy>
       <xsl:apply-templates select="@* | node()" />
          <xsl:if test=" . = /Job/Queue/EventDrivenSubmission/SchedulerInformation">
                <xsl:element name="resource">
                              <xsl:call-template name="CALCULATE_RESOURCES"/>
                </xsl:element>
          </xsl:if>

</xsl:copy>
</xsl:template>

<xsl:template name="CALCULATE_RESOURCES">
    <xsl:for-each select="//Transform/DataStore">
            <xsl:if test="starts-with(@name, $mount)">
                    <xsl:element name="name">
                        <xsl:value-of select="$dataval"/>
                    </xsl:element>
            </xsl:if>
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>
**********************************************

Expected Output:
**********************************************
<?xml version="1.0" encoding="ISO-8859-1"?>
<Job id="WFG" submitType="publishAndSubmit" submitRun="true">
    <Engine configurationFile="GENERATE_CONFIG_FILE">
        <Parameter id="Env">/mnt/wfg_2.1/etc/US_WFG_Dev.env</Parameter>
        <Parameter id="SEQ">No</Parameter>
        <Parameter id="DOMAIN"/>
        <Parameter id="LINK_TYPE"/>
    </Engine>
    <Queue id="cii" emailAddress="*******">
        <Billing id="billing_standard">
            <Parameter id="LIN">202142</Parameter>
            <Parameter id="PRO">2VY06</Parameter>
            <Parameter id="FIL">203</Parameter>
            <Parameter id="GL">12380</Parameter>
            <Parameter id="BU">ESI</Parameter>
        </Billing>
    <EventDrivenSubmission>
<SchedulerInformation id="f3c61afa-bbd6-1004-8f0f78ded200a8e7">
<resource>
<name>DATAGRID</name>
</resource>
</SchedulerInformation>

            <NotificationList>
                <Notification>
                    <JobEvent id="Job Submitted"/>
                    <JobEvent id="Job Initiated"/>
                    <JobEvent id="Job Queued"/>
                    <JobEvent id="Job Started"/>
                    <JobEvent id="Job Ended"/>
                    <JobEvent id="Job Cancelled"/>
                    <JobEvent id="Job Held"/>
                </Notification>
            </NotificationList>
        </EventDrivenSubmission>
    </Queue>
    <Transform>
        <DataStore name="/mnt/datagrid1/DEFT/" location="ftpsharedev">
            <RecordLayout>
                <Field fieldDelimiter="none"/>
            </RecordLayout>
        </DataStore>
    </Transform>
</Job>
**********************************************

My Output:
**********************************************
<?xml version="1.0" encoding="ISO-8859-1"?>
<Job id="WFG" submitType="publishAndSubmit" submitRun="true">
<Engine configurationFile="GENERATE_CONFIG_FILE">
<Parameter id="Env">/mnt/wfg_2.1/etc/US_WFG_Dev.env</Parameter>
<Parameter id="SEQ">No</Parameter>
<Parameter id="DOMAIN">
<resource>
<name>DATAGRID</name>
</resource>
</Parameter>
<Parameter id="LINK_TYPE">
<resource>
<name>DATAGRID</name>
</resource>
</Parameter>
</Engine>
<Queue id="cii" emailAddress="*******">
<Billing id="billing_standard">
<Parameter id="LIN">202142</Parameter>
<Parameter id="PRO">2VY06</Parameter>
<Parameter id="FIL">203</Parameter>
<Parameter id="GL">12380</Parameter>
<Parameter id="BU">ESI</Parameter>
</Billing>
<EventDrivenSubmission>
<SchedulerInformation id="f3c61afa-bbd6-1004-8f0f-78ded200a8e7">
<resource>
<name>DATAGRID</name>
</resource>
</SchedulerInformation>
<NotificationList>
<Notification>
<JobEvent id="Job Submitted">
<resource>
<name>DATAGRID</name>
</resource>
</JobEvent>
<JobEvent id="Job Initiated">
<resource>
<name>DATAGRID</name>
</resource>
</JobEvent>
<JobEvent id="Job Queued">
<resource>
<name>DATAGRID</name>
</resource>
</JobEvent>
<JobEvent id="Job Started">
<resource>
<name>DATAGRID</name>
</resource>
</JobEvent>
<JobEvent id="Job Ended">
<resource>
<name>DATAGRID</name>
</resource>
</JobEvent>
<JobEvent id="Job Cancelled">
<resource>
<name>DATAGRID</name>
</resource>
</JobEvent>
<JobEvent id="Job Held">
<resource>
<name>DATAGRID</name>
</resource>
</JobEvent>
</Notification>
</NotificationList>
</EventDrivenSubmission>
</Queue>
<Transform>
<DataStore name="/mnt/datagrid1/DEFT/" location="ftpsharedev">
<RecordLayout>
<Field fieldDelimiter="none">
<resource>
<name>DATAGRID</name>
</resource>
</Field>
</RecordLayout>
</DataStore>
</Transform>
</Job>

**********************************************


Reply With Quote
  #2 (permalink)  
Old November 11th, 2005, 07:44 AM
Authorized User
 
Join Date: Jul 2004
Location: Oxford, , United Kingdom.
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Solution is below:

Your line:

  <xsl:if test=" . = /Job/Queue/EventDrivenSubmission/SchedulerInformation">

will compare the text values of the current node and SchedulerInformation.

Regards
Bryan

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

       <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes" />


    <xsl:variable name="mount" select="'/mnt/datagrid'"/>
    <xsl:variable name="dataval" select="'DATAGRID'"/>


<xsl:template match="/ | @* | * | comment() | processing-instruction() | text()">
    <xsl:copy>
        <xsl:apply-templates select="@* | * | comment() | processing-instruction() | text()"/>
    </xsl:copy>
</xsl:template>


<xsl:template match="SchedulerInformation">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()" />
        <xsl:for-each select="//Transform/DataStore">
            <resource>
                <xsl:if test="starts-with(@name, $mount)">
                    <name><xsl:value-of select="$dataval"/></name>
                </xsl:if>
            </resource>
        </xsl:for-each>

    </xsl:copy>
</xsl:template>

</xsl:stylesheet>



Reply With Quote
Reply


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
xsl:copy-of Issue DKatSSA BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 8 November 19th, 2008 05:18 PM
How can i use xsl:copy-of in xsl sampath.bandaru XSLT 11 October 1st, 2008 03:37 AM
Chapter 2 - Using copies of virtual machine fails Jvillalobos BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 1 July 8th, 2008 05:10 PM
Copy one node to another in XSL hugoscp XML 5 September 14th, 2006 09:40 AM
Slightly modified xsl:copy-of arcuza XSLT 6 April 10th, 2006 04:53 AM



All times are GMT -4. The time now is 05:01 PM.


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