Here is my usecase:
I have two collections. First collection is having large no.of records and other one is having few records.
Here is the xsd for these 2 collections:
Here is the sample xsd file that I have used for XSLT mapping:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 | <?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://beta.example.org"
xmlns:a="http://beta.example.org" targetNamespace="http://beta.example.org" elementFormDefault="qualified">
<xsd:element name="employees">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="employee" type="a:employee" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="employee">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="salary" type="xsd:integer"/>
<xsd:element name="age" type="xsd:integer"/>
<xsd:element name="id" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="person">
<xsd:sequence>
<xsd:element name="id" type="xsd:integer"/>
<xsd:element name="name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="persons">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="person" type="a:person" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="output">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="worker" type="a:employee" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
|
Here I have used 2 collections: employees and persons as input to XSLT and "output" as outcome of XSLT. Now, I want to eliminate
employees whose IDs are matching with IDs in
persons.
Here is the XSLT I have created for achieving this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 | <xsl:param name="input2"/>
<xsl:variable name="values" >
,<xsl:for-each select="$input2/ns0:persons/ns0:person"><xsl:value-of select="./ns0:id"/>,</xsl:for-each>
</xsl:variable>
<!-- document('')/xsl:stylesheet/ns0:persons/ns0:person/ns0:id
$input2/ns0:persons/ns0:person/ns0:id
-->
<xsl:template match="/">
<ns0:output>
<xsl:for-each select="/ns0:employees/ns0:employee">
<xsl:if test="not(contains($values, concat(',', current()/ns0:id, ',')))">
<ns0:worker>
<ns0:id>
<xsl:value-of select="current()/ns0:id"/>
</ns0:id>
</ns0:worker>
</xsl:if>
</xsl:for-each>
</ns0:output>
</xsl:template>
|
Details of this implementation:
I have created a variable
values which will have all the IDs of
persons eg. ",1,2,3,". Then
employees iterated and checks for it's ID in
values. If not, then that record will be mapped to
output.