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>
**********************************************
|