I am preety new to XSLT and thats my first Question in stackoverflow.
The Problem is that I have a System Generated XML like this one:
<?xml version="1.0" encoding="utf-16"?>
<Record contentId="1">
<Field1>
<ListValues>
<ListValue id="84994" displayName="Infrastructure Platform:Database Management (ODP)">Database Management (ODP)</ListValue>
</ListValues>
</Field1>
<Field2>
<ListValues>
<ListValue id="84992" displayName="Infrastructure Platform:Application Server (ODP)">Application Server (ODP)</ListValue>
</ListValues>
</Field2>
<Field3>
<Reference id="7">Name-Record</Reference>
<Reference id="8">Name-Record</Reference>
</Field3>
</Record>
<Record contentId="2">
<Field1>
<ListValues>
<ListValue id="84992" displayName="Infrastructure Platform:Application Server (ODP)">Application Server (ODP)</ListValue>
</ListValues>
</Field1>
<Field2>
<ListValues>
<ListValue id="84992" displayName="Infrastructure Platform:Application Server (ODP)">Application Server (ODP)</ListValue>
<ListValue id="84993" displayName="Infrastructure Platform:Web Server (ODP)">Web Server (ODP)</ListValue>
<ListValue id="84994" displayName="Infrastructure Platform:Database Management (ODP)">Database Management (ODP)</ListValue>
<ListValue id="84998" displayName="Infrastructure Platform:Virtualization (ODP)">Virtualization (ODP)</ListValue>
<ListValue id="84999" displayName="Infrastructure Platform:Storage Management (ODP)">Storage Management (ODP)</ListValue>
</ListValues>
</Field2>
<Field3>
<Reference id="3">Name-Record</Reference>
<Reference id="4">Name-Record</Reference>
</Field3>
</Record>
<Record contentId="3">
<Field1>
<ListValues>
<ListValue id="84994" displayName="Infrastructure Platform:Database Management (ODP)">Database Management (ODP)</ListValue>
</ListValues>
</Field1>
<Field2>
<ListValues>
<ListValue id="84992" displayName="Infrastructure Platform:Application Server (ODP)">Application Server (ODP)</ListValue>
<ListValue id="84993" displayName="Infrastructure Platform:Web Server (ODP)">Web Server (ODP)</ListValue>
<ListValue id="84994" displayName="Infrastructure Platform:Database Management (ODP)">Database Management (ODP)</ListValue>
</ListValues>
</Field2>
<Field3>
<Reference id="4">Name-Record</Reference>
<Reference id="1">Name-Record</Reference>
</Field3>
</Record>
Record 4
<Record contentId="4">
<Field1>
<ListValues>
<ListValue id="84992" displayName="Infrastructure Platform:Application Server (ODP)">Application Server (ODP)</ListValue>
</ListValues>
</Field1>
<Field2>
<ListValues>
<ListValue id="84992" displayName="Infrastructure Platform:Application Server (ODP)">Application Server (ODP)</ListValue>
<ListValue id="84993" displayName="Infrastructure Platform:Web Server (ODP)">Web Server (ODP)</ListValue>
<ListValue id="84994" displayName="Infrastructure Platform:Database Management (ODP)">Database Management (ODP)</ListValue>
</ListValues>
</Field2>
<Field3>
<Reference id="1">Name-Record</Reference>
</Field3>
</Record>
What I want to achive is:
- It needs to find matches where my Field1 have a Match in the other records with Field2.
- Than I need to look if the Previous Match is also the same Record which is in Field3.
For Example: Record 1 have in Field1 "Database Management (ODP)" management, now he looks for matches, he will find Record 2,3 and 4. Now he needs too look if in Field3 is Record 1. Result is than Record 3 and Record 4.
To achive this I have build something like this(I know it's not accurate, this is only for example the real Stylesheet with the real paths and nodes is working):
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<archer_records>
<xsl:for-each select="Record">
<xsl:variable name="ParentRecordId" select="@contentId"/>
<!--Field1 Check -->
<xsl:choose>
<xsl:when test="Field1/ListValues/ListValue">
<xsl:for-each select="Field1/ListValues/ListValue">
<xsl:variable name="ParentType" select="@displayName"/>
<xsl:for-each select="../../../../Record">
<xsl:choose>
<xsl:when test="Field2/ListValues/ListValue">
<xsl:for-each select="Field2/ListValues/ListValue">
<!--Field3 Check -->
<xsl:variable name="ChildType" select="@displayName"/>
<xsl:if test="$ParentType=$ChildType">
<xsl:variable name="ChildRecordID" select="../../../@contentId"/>
<xsl:choose>
<xsl:when test="../../../Field3">
<xsl:for-each select="Field3[@id=$SPI_Tracking_Haupt]">
<record>
<ParentRecord>
<xsl:value-of select="$ParentrecordID" />
</ParentRecord>
<ChildRecord>
<xsl:value-of select="$ChildRecordID" />
</ChildRecord>
</record>
</xsl:for-each>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</archer_records>
</xsl:template>
</xsl:stylesheet>
Thats working. I am getting a Result like this:
<record>
<ParentRecord>1</ParentRecord>
<ChildRecord>3</ChildRecord>
</record>
<record>
<ParentRecord>1</ParentRecord>
<ChildRecord>4</ChildRecord>
</record>
<record>
<ParentRecord>2</ParentRecord>
<ChildRecord>3</ChildRecord>
</record>
<record>
<ParentRecord>4</ParentRecord>
<ChildRecord>3</ChildRecord>
</record>
But I want something like this:
<record>
<ParentRecord>1</ParentRecord>
<ChildRecord>3</ChildRecord>
<ChildRecord>4</ChildRecord>
</record>
<record>
<ParentRecord>2</ParentRecord>
<ChildRecord>3</ChildRecord>
</record>
<record>
<ParentRecord>4</ParentRecord>
<ChildRecord>3</ChildRecord>
</record>
I hope someone could Understand what my Problem is.
Thank you!