XSL evaluate dynamic XPATH from another document - xslt

I have two sample documents defined below. In module_meta.xml only the effect nodes on xpath /mdata/effectivity are relevant. As seen below, they contain a path attribute and a effrg attribute. The goal is now to evaluate the xpath (which is defined in the module_meta.xml as the path attribute) on the module.xml and append the effrg to it. See desired_output.xml for the desired result. The xsl transformation is applied on module.xml. I know that I have to use the document() function to "include" module_meta.xml, but so far I am at a loss.
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE proc>
<procbody>
<info>
<action lid="a">
</action>
<action lid="b">
</action>
<action lid="c">
</action>
</info>
</procbody>
module_meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mdata>
<mdata>
<metadata>
<metadata-item name="n1" value="v1" />
<metadata-item name="n2" value="v2" />
<metadata-item name="n3" value="v3" />
</metadata>
<effectivity>
<effect path="//*[#lid='a']" effrg="0074 0080 0087" />
<effect path="//*[#lid='b']" effrg="0136 0146 0174" />
</effectivity>
</mdata>
desired_output.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE proc>
<procbody>
<info>
<action lid="a" effrg="0074 0080 0087">
</action>
<action lid="b" effrg="0136 0146 0174">
</action>
<action lid="c">
</action>
</info>
</procbody>

In XSLT 3 with xsl:evaluate support:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
xmlns:mf="http://example.com/mf"
expand-text="yes">
<xsl:function name="mf:evaluate" as="element(action)?">
<xsl:param name="effect" as="element(effect)"/>
<xsl:evaluate xpath="$effect/#path" context-item="$main-doc"/>
</xsl:function>
<xsl:variable name="main-doc" select="/"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="info/action">
<xsl:copy>
<xsl:apply-templates select="#*, $meta//effect[current() is mf:evaluate(.)]/#effrg"/>
</xsl:copy>
</xsl:template>
<xsl:param name="meta">
<mdata>
<metadata>
<metadata-item name="n1" value="v1" />
<metadata-item name="n2" value="v2" />
<metadata-item name="n3" value="v3" />
</metadata>
<effectivity>
<effect path="//*[#lid='a']" effrg="0074 0080 0087" />
<effect path="//*[#lid='b']" effrg="0136 0146 0174" />
</effectivity>
</mdata>
</xsl:param>
</xsl:stylesheet>
For self-containedness of the example the second document is inline as a parameter but you can of course use <xsl:param name="meta" select="doc('module_meta.xml')"/> instead.
It might be much more efficient to use the xsl:evaluate only once for each effect element, for instance, by declaring a key doing that, and store the generated-id if there is one:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
xmlns:mf="http://example.com/mf"
expand-text="yes">
<xsl:key name="ref" match="mdata/effectivity/effect">
<xsl:variable name="referenced-node" as="node()?">
<xsl:evaluate xpath="#path" context-item="$main-doc" as="node()?"/>
</xsl:variable>
<xsl:sequence select="generate-id($referenced-node)"/>
</xsl:key>
<xsl:variable name="main-doc" select="/"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="info/action">
<xsl:copy>
<xsl:apply-templates select="#*, key('ref', generate-id(), $meta)/#effrg"/>
</xsl:copy>
</xsl:template>
<xsl:param name="meta">
<mdata>
<metadata>
<metadata-item name="n1" value="v1" />
<metadata-item name="n2" value="v2" />
<metadata-item name="n3" value="v3" />
</metadata>
<effectivity>
<effect path="//*[#lid='a']" effrg="0074 0080 0087" />
<effect path="//*[#lid='b']" effrg="0136 0146 0174" />
</effectivity>
</mdata>
</xsl:param>
</xsl:stylesheet>
If you want to match any element referenced in the other document and copy any attribute but the path one you could change the template having match="info/action" to
<xsl:template match="*[key('ref', generate-id(), $meta)]">
<xsl:copy>
<xsl:apply-templates select="#*, key('ref', generate-id(), $meta)/(#* except #path), node()"/>
</xsl:copy>
</xsl:template>

Related

Selecting distinct values from XSLT sub query

I have this XML document:
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<properties>
<property name="prop1" type="type1"/>
<property name="prop2" type="type2"/>
<property name="prop3" type="type3"/>
<property name="prop4" type="type1"/>
</properties>
<types>
<type name="type1" group="group1"/>
<type name="type2" group="group1"/>
<type name="type3" group="group2"/>
<type name="type4" group="group3"/>
</types>
<groups>
<group name="group1" owner="owner1"/>
<group name="group2" owner="owner2"/>
<group name="group3" owner="owner3"/>
</groups>
</metadata>
I am transforming it using this XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="docRoot" select="/" />
<xsl:for-each select="distinct-values($docRoot/metadata/properties/property/#type)">
<xsl:variable name="groupOwner" select="$docRoot/metadata/groups/group[#name=$docRoot/metadata/types/type[#name=current()]/#group]/#owner" />
<xsl:value-of select="$groupOwner"/><xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
What I want to do is print out the list of unique group owners for all of the properties in the document. I'm successfully filtering out duplicate types with distinct-values but can't see how to filter out duplicate owners.
The current output:
owner1
owner1
owner2
The required output:
owner1
owner2
If it helps no two groups have the same owner.
Keys can be your friend here...
<xsl:key name="types" match="type" use="#name" />
<xsl:key name="groups" match="group" use="#name" />
Then you can do this, without even any need for distinct-values because you won't get duplicate nodes returned this way:
<xsl:for-each select="key('groups', key('types', metadata/properties/property/#type)/#group)">
For example, try this XSLT
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:key name="types" match="type" use="#name" />
<xsl:key name="groups" match="group" use="#name" />
<xsl:template match="/">
<xsl:for-each select="key('groups', key('types', metadata/properties/property/#type)/#group)">
<xsl:value-of select="concat(#owner, '
')" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
In fact, you can simplify the xsl:for-each to this:
<xsl:value-of select="key('groups', key('types', metadata/properties/property/#type)/#group)/#owner" separator="
" />
Ah, just needed to try a bit harder:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="docRoot" select="/" />
<xsl:for-each select="distinct-values($docRoot/metadata/groups/group[#name=$docRoot/metadata/types/type[#name=$docRoot/metadata/properties/property/#type]/#group]/#owner)">
<xsl:value-of select="current()"/><xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Open to any suggestions for simplifying this though!

Removing duplicate records from xml

<?xml version="1.0" encoding="utf-8"?>
<Employee_Data>
<Employee>
<NEW_HIRE_OR_REHIRE />
<RETIREMENT_BENEFITS />
<ADDRESS />
<PERSONAL>
<Record>
<SSN>327408678</SSN>
<WDEmpID>10032417</WDEmpID>
<Initiator />
<Effective>20141014</Effective>
<SeqNum>320</SeqNum>
<Last_Name>VAN TREECK</Last_Name>
<First_Name>DENISE</First_Name>
<Middle_Name>J</Middle_Name>
<Social_Suffix />
<Birth_Date>19560422</Birth_Date>
<Gender>F</Gender>
<Ethnicity>0</Ethnicity>
<Marital_Status_Date>19781202</Marital_Status_Date>
<Marital_Status>M</Marital_Status>
<CITIZENSHIP />
<Military_Service_Status />
<Disability />
<Indicator>PersonalRecordChangesIndicator</Indicator>
</Record>
</PERSONAL>
<STATUS />
<POSITION>
<Record>
<SSN>327408678</SSN>
<WDEmpID>10032417</WDEmpID>
<Initiator />
<Effective>20141006</Effective>
<SeqNum>250</SeqNum>
<ActionCode />
<DEFAULTJOBCODE>YYY01</DEFAULTJOBCODE>
<SAPJOBCODE>30000715</SAPJOBCODE>
<PayEntity>NC1</PayEntity>
<DIVISION>CORP</DIVISION>
<ORGANIZATION>GES</ORGANIZATION>
<COMPANYNUMBER>01</COMPANYNUMBER>
<LEDGERDEPARTMENT>CHEN050D</LEDGERDEPARTMENT>
<SALARY_GRADE>LC008</SALARY_GRADE>
<TEMPORARY_POSITION_INDICATOR_FOR_POSITION_RECORD />
<LocationCode>AP10</LocationCode>
<LocationDepartment>050D</LocationDepartment>
<WDEmpID>10032417</WDEmpID>
<Indicator>Position and Location Change Indicator</Indicator>
</Record>
<Record>
<SSN>327408678</SSN>
<WDEmpID>10032417</WDEmpID>
<Initiator />
<Effective>20141006</Effective>
<SeqNum>250</SeqNum>
<ActionCode />
<DEFAULTJOBCODE>YYY01</DEFAULTJOBCODE>
<SAPJOBCODE>30000715</SAPJOBCODE>
<PayEntity>NC1</PayEntity>
<DIVISION>CORP</DIVISION>
<ORGANIZATION>GES</ORGANIZATION>
<COMPANYNUMBER>01</COMPANYNUMBER>
<LEDGERDEPARTMENT>CHEN050D</LEDGERDEPARTMENT>
<SALARY_GRADE>LC008</SALARY_GRADE>
<TEMPORARY_POSITION_INDICATOR_FOR_POSITION_RECORD />
<LocationCode>AP10</LocationCode>
<LocationDepartment>050D</LocationDepartment>
<WDEmpID>10032417</WDEmpID>
<Indicator>Position and Location Department change Indicator
</Indicator>
</Record>
</POSITION>
<COMPENSATION />
<SALES_TERRITORY />
<TERMINATION />
</Employee>
</Employee_Data>
This is an xml generated by 1 xslt. I basically want to check if 2 records under Position tab are similar then keep only 1 else keep both of them. In this case the output should be like as given below.
<?xml version="1.0" encoding="utf-8"?>
<Employee_Data>
<Employee>
<NEW_HIRE_OR_REHIRE />
<RETIREMENT_BENEFITS />
<ADDRESS />
<PERSONAL>
<Record>
<SSN>327408678</SSN>
<WDEmpID>10032417</WDEmpID>
<Initiator />
<Effective>20141014</Effective>
<SeqNum>320</SeqNum>
<Last_Name>VAN TREECK</Last_Name>
<First_Name>DENISE</First_Name>
<Middle_Name>J</Middle_Name>
<Social_Suffix />
<Birth_Date>19560422</Birth_Date>
<Gender>F</Gender>
<Ethnicity>0</Ethnicity>
<Marital_Status_Date>19781202</Marital_Status_Date>
<Marital_Status>M</Marital_Status>
<CITIZENSHIP />
<Military_Service_Status />
<Disability />
<Indicator>PersonalRecordChangesIndicator</Indicator>
</Record>
</PERSONAL>
<STATUS />
<POSITION>
<Record>
<SSN>327408678</SSN>
<WDEmpID>10032417</WDEmpID>
<Initiator />
<Effective>20141006</Effective>
<SeqNum>250</SeqNum>
<ActionCode />
<DEFAULTJOBCODE>YYY01</DEFAULTJOBCODE>
<SAPJOBCODE>30000715</SAPJOBCODE>
<PayEntity>NC1</PayEntity>
<DIVISION>CORP</DIVISION>
<ORGANIZATION>GES</ORGANIZATION>
<COMPANYNUMBER>01</COMPANYNUMBER>
<LEDGERDEPARTMENT>CHEN050D</LEDGERDEPARTMENT>
<SALARY_GRADE>LC008</SALARY_GRADE>
<TEMPORARY_POSITION_INDICATOR_FOR_POSITION_RECORD />
<LocationCode>AP10</LocationCode>
<LocationDepartment>050D</LocationDepartment>
<WDEmpID>10032417</WDEmpID>
<Indicator>Position and Location Change Indicator</Indicator>
</Record>
</POSITION>
<COMPENSATION />
<SALES_TERRITORY />
<TERMINATION />
</Employee>
</Employee_Data>
To remove the duplicate records, you can use Muenchian Grouping:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="no" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="seqNumByRecord" match="Record" use="SeqNum"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match=
"Record[not(generate-id() = generate-id(key('seqNumByRecord', SeqNum)[1]))]"
/>
</xsl:stylesheet>
The first template is an identity transform that matches all attributes and nodes and copies them. The second template is an empty template that matches all duplicates. Because the template is empty, these Records will be removed. For a detailed explanation of Muenchian Grouping this article by Jeni Tennison is recommended: http://www.jenitennison.com/xslt/grouping/muenchian.html, and you will also find many excellent answers on Stackoverflow.
For variety, a second solution:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Record[SeqNum = following::Record/SeqNum]"/>
</xsl:stylesheet>
In this approach, the empty template for removing the duplicates matches all Records that have the same SeqNum as following Records. As you'll find in the mentioned article, the Muenchian method is considered to be more efficient.

Transformation of text file into an xml using datapower

I want to transfer a non-xml text file delimited by '|' characters into an xml using Datapower.
Following is file (sample1)
10|20003|24/23/25|23890
Now i have to break this into the following XML
<ResponseType>
<ResCode>10</ResCode>
<Id>20003</Id>
<SoftCode>24/23/25</SoftCode>
<StatusCode>23890</StatusCode>
</ResponseType>
What I did was following--
1>Create a Transform action in the service that will be receiving non-XML requests.
2>Select "Use XSLT specified in this action on a non-XML message" to specify that this is a Binary Transform.
3>Upload the following stylesheet as the Processing Control File.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
version="1.0">
<dp:input-mapping href="sample1.ffd" type="ffd"/>
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:copy-of select="ResponseType"/>
<xsl:call-template name="str:tokenize">
<xsl:with-param name="string" select="string" />
</xsl:call-template>
</xsl:template>
<xsl:template name="str:tokenize">
<xsl:with-param name="string" select="">
str:tokenize('string', '|')
</xsl:with param>
</xsl:template>
</xsl:stylesheet>
and here is my sample1.ffd(which I have uploaded in my local:// directory in Datapower
<File name="ResponseType">
<!-- capture all data into this tag -->
<Field name="ResCode/Id/SoftCode/StatusCode" />
</File>
But I am not getting desired output , I think my xslt is quite wrong
What can I do do to get desired output?
In DataPower using FFD the following should work:
1) Add the FFD file (below one of my old education samples):
<File name="CSVFILE">
<Group name="CSVLine" minOccurs="0" maxOccurs="unbounded" delim="\n">
<Field name="id"/>
<Field name="fname" delim=","/>
<Field name="lname" delim=","/>
<Field name="title" delim=","/>
<Field name="dept" delim=","/>
<Field name="org"/>
</Group>
</File>
2) Add the XSLT (this one simply copies the FFD transformed XML to output):
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
version="1.0">
<dp:input-mapping href="CSVFILE.FFD" type="ffd"/>
<!-- This stylesheet copies the input to the output -->
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
3) Send a message:
1,Anders,Wasen,B2B Architect,DataPower Dev,Enfo Zystems
2,Jean-Luc,Piccard,Captain,USS Enterprise,Star Fleet
4) This will result in the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<CSVFILE>
<CSVLine>
<id>1</id>
<fname>Anders</fname>
<lname>Wasen</lname>
<title>B2B Architect</title>
<dept>DataPower Dev,Enfo Zystems</dept>
<org/>
</CSVLine>
<CSVLine>
<id>2</id>
<fname>Jean-Luc</fname>
<lname>Piccard</lname>
<title>Captain</title>
<dept>USS Enterprise,Star Fleet</dept>
<org/>
</CSVLine>
</CSVFILE>
Make sure that you change the XSLT Transform action into "Transform Binary" and set Request Type to "non-xml", else it will not work!
Hope this will help you! :)
I'm not sure how IBM Datapower might solve this problem, but for XSLT, you would at least wrap your input in a XML element:
<Whatever>
10|20003|24/23/25|23890
</Whatever>
And then you could go on with a transformation like follows. The hard part is splitting your text input. In XSLT 1.0, there is no function available for that, so you need a recursive template.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" version="1.0" exclude-result-prefixes="msxml">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:variable name="tokenized">
<items>
<xsl:call-template name="tokenize">
<xsl:with-param name="string" select="//text()" />
</xsl:call-template>
</items>
</xsl:variable>
<ResponseType>
<ResCode>
<xsl:copy-of select="msxml:node-set($tokenized)/items/item[1]/text()" />
</ResCode>
<Id>
<xsl:copy-of select="msxml:node-set($tokenized)/items/item[2]/text()" />
</Id>
<SoftCode>
<xsl:copy-of select="msxml:node-set($tokenized)/items/item[3]/text()" />
</SoftCode>
<StatusCode>
<xsl:copy-of select="msxml:node-set($tokenized)/items/item[4]/text()" />
</StatusCode>
</ResponseType>
</xsl:template>
<xsl:template name="tokenize">
<xsl:param name="string" />
<xsl:variable name="item" select="normalize-space( substring-before( concat( $string, '|'), '|'))" />
<xsl:if test="$item">
<item>
<xsl:value-of select="$item" />
</item>
<xsl:call-template name="tokenize">
<xsl:with-param name="string" select="substring-after($string,'|')" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

Convert string value as XML tag name

Below is my requirement. Can we do this using XSLT? I want to convert value of AttributeName as tag under policy and corresponding AttributeValue as value.
Input :
<Policy>
<Attributes>
<AttributeName>is_policy_loan</AttributeName>
<AttributeValue>Yes</AttributeValue>
</Attributes>
<Attributes>
<AttributeName>is_policy_owners</AttributeName>
<AttributeValue>Yes</AttributeValue>
</Attributes>
<Attributes>
<AttributeName>is_policy_twoyears</AttributeName>
<AttributeValue>Yes</AttributeValue>
</Attributes>
</Policy>
Output :
<Policy>
<is_policy_loan>Yes</is_policy_loan>
<is_policy_owners>Yes</is_policy_owners>
<is_policy_twoyears>Yes</is_policy_twoyears>
</Policy>
The following xsl file will do the job:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- create the <AttributeName>AttributeValue</..> nodes -->
<xsl:template match="//Attributes">
<xsl:variable name="name" select="AttributeName" />
<xsl:element name="{$name}">
<xsl:value-of select="AttributeValue" />
</xsl:element>
</xsl:template>
<!-- wrap nodes in a `Policy` node -->
<xsl:template match="/">
<Policy>
<xsl:apply-templates/>
</Policy>
</xsl:template>
</xsl:stylesheet>
The way i would do,
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" encoding="UTF-8" omit-xml-declaration="yes" />
<xsl:template match="Policy">
<xsl:element name="Policy">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="Attributes">
<xsl:variable name="name" select="AttributeName" />
<xsl:element name="{$name}">
<xsl:value-of select="AttributeValue" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
output will be,
<Policy>
<is_policy_loan>Yes</is_policy_loan>
<is_policy_owners>Yes</is_policy_owners>
<is_policy_twoyears>Yes</is_policy_twoyears>
</Policy>

how to put condition on xsl:result-document output according to attribute value

i am transforming XML using Saxon parser.i have to generate same output with two place that i am able to do that.i want to put the condition like if count attribute value is 0 then it should not generate any output file. my input file is
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getDocumentByKeyResponsexmlns:ns1="http://www.taleo.com/ws/integration/toolkit/2005/07" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<Document xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07">
<Attributes>
<Attribute name="duration">0:00:00.789</Attribute>
<Attribute name="count">0</Attribute>
<Attribute name="entity">SourcingRequest</Attribute>
<Attribute name="mode">XML</Attribute>
<Attribute name="version">http://www.taleo.com/ws/tee800/2009/01</Attribute>
</Attributes>
<Content>
<ExportXML xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07"/>
</Content>
</Document>
</ns1:getDocumentByKeyResponse>
</soapenv:Body>
</soapenv:Envelope>
my xsl file is like this .
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" encoding="utf-8"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pDest" select="'file:///c:/temp/'"/>
<xsl:param name="pDest1" select="'file:///c:/'"/>
<xsl:template match="*:field">
<xsl:element name="{lower-case(#name)}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="/">
<xsl:result-document
href="{$pDest}requsition_{format-date(current-date(),'[D01]_[M01]')}.xml">
<JobPositionPostings>
<xsl:apply-templates select="descendant::*:Content[1]" />
</JobPositionPostings>
</xsl:result-document>
<xsl:result-document
href="{$pDest1}requsition_{format-date(current-date(),'[D01]_[M01]')}.xml">
<JobPositionPostings>
<xsl:apply-templates select="descendant::*:Content[1]" />
</JobPositionPostings>
</xsl:result-document>
</xsl:template>
<xsl:template match="*:record">
<!--doing rest operation if attribute count not equal to 0 -->
</xsl:template>
</xsl:stylesheet>
I think you want to replace the template
<xsl:template match="/">
<xsl:result-document
href="{$pDest}requsition_{format-date(current-date(),'[D01]_[M01]')}.xml">
<JobPositionPostings>
<xsl:apply-templates select="descendant::*:Content[1]" />
</JobPositionPostings>
</xsl:result-document>
<xsl:result-document
href="{$pDest1}requsition_{format-date(current-date(),'[D01]_[M01]')}.xml">
<JobPositionPostings>
<xsl:apply-templates select="descendant::*:Content[1]" />
</JobPositionPostings>
</xsl:result-document>
</xsl:template>
somehow with
<xsl:template match="/">
<xsl:if test="soapenv:Envelope/soapenv:Body/ns1:getDocumentByKeyResponse/df:Document/df:Attributes/df:Attribute[#name = 'count'] != 0">
<xsl:result-document
href="{$pDest}requsition_{format-date(current-date(),'[D01]_[M01]')}.xml">
<JobPositionPostings>
<xsl:apply-templates select="descendant::*:Content[1]" />
</JobPositionPostings>
</xsl:result-document>
<xsl:result-document
href="{$pDest1}requsition_{format-date(current-date(),'[D01]_[M01]')}.xml">
<JobPositionPostings>
<xsl:apply-templates select="descendant::*:Content[1]" />
</JobPositionPostings>
</xsl:result-document>
</xsl:if>
</xsl:template>
where you additionally declare
<xsl:stylesheet xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://www.taleo.com/ws/integration/toolkit/2005/07"
xmlns:df="http://www.taleo.com/ws/integration/toolkit/2005/07"
exclude-result-prefixes="soapenv ns1 df"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
That way the two xsl:result-document instructions you have are only executed if the condition is true.