Dear all,
I was wondering if it is possible to use <xsl:apply-templates> to apply changes to a specific (not current) location of the original xml file.
Imagine an xml file composed by many repetitions of the following pattern (i.e. many grandfathers). For brevity all nodes are empty, but this is not the case in the real file.
Code:
<grandfather>
<father/>
<child/>
<grandson/>
<mother/>
<child/>
<grandson/>
</grandfather>
What I would like to do is the following:
Code:
<xsl:template match="/">
<xsl:for-each select="grandfather/father/child">
<!-- if specific condition "A" on a grandson's attribute holds -->
<xsl:result-document ...>
<xsl:apply-templates select="$document"/>
</xsl:result-document ...>
</xsl:for-each>
</xsl:template>
<xsl:template match="grandfather/father/child">
<!-- if condition "A" on a grandson's attribute holds -->
Apply CHANGES HERE
<!-- if a specific condition "B" on current()/parent::*/parent::*/mother/child holds-->
<xsl:apply-templates ... mode="mother" />
</xsl:template>
<identity-template>
to copy everything that has to remain as it is
</identity-template>
<xsl:template ... mode="mother">
changes to mother's child
</xsl:template>
The problem is that the changes to the mother's child are introduced in the "grandfather/father/child" path, because the apply-templates tag is inside the xsl:template command matching "grandfather/father/child". And I want to generate a file for each occurrence of a "grandfather/father/child" for which the specific condition A holds.
Is there any way to tell where the result of the application of templates should be put? or do I have to chenge the script in order to do a for-each on "grandfather" nodes and then examine the two inner nodes ("father" and "mother") to check if the conditions hold and rebuild them accordingly to the changes I want to apply?
I hope I was clear enough
Best,
Eastvan