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 November 10th, 2005, 10:21 PM
Registered User
 
Join Date: Jul 2005
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>

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


 
Old November 11th, 2005, 07:44 AM
Authorized User
 
Join Date: Jul 2004
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>








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





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