Subject: RE: Searching in Sub-children from an Array
From: "Houman Khorasani" <Houman.Khorasani@xxxxxxxxxxx>
Date: Thu, 15 Feb 2007 12:21:45 -0000
|
Hello,
May I rephrase my question, please?
XML Input:
<tree>
<fruit ID="111">
<mango ID="333">
<colour>
<Rate_Structure_Event>
<Rate ConceptType="Rate_Event">
<Added_Unit_Rate>909000</Added_Unit_Rate>
</Rate>
<Rate ConceptType="Rate_Event">
<Added_Unit_Rate>889000</Added_Unit_Rate>
</Rate>
</Rate_Structure_Event>
</colour>
</mango>
<orange ID="222">
<color>orange</color>
</orange>
</fruit>
<fruit_adjustment>
<color>
<Path>
<Steps>111,333</Steps>
</Path>
<Rate_Event ConceptType="Rate_Event">
<Added_Unit_Rate>3000</Added_Unit_Rate>
</Rate_Event>
<Rate_Event ConceptType="Rate_Event">
<Added_Unit_Rate>2000</Added_Unit_Rate>
</Rate_Event>
</color>
</fruit_adjustment>
</tree>
XSLT 2.0:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="step" match="fruit_adjustment/color//Rate_Event"
use="../Path/Steps"/>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="fruit_adjustment"/>
<xsl:template match="colour">
<xsl:copy-of
select="(key('step',string-join(ancestor-or-self::*[@ID]/@ID,',')),.)[*]
"/>
</xsl:template>
</xsl:stylesheet>
Expected Output:
<tree>
<fruit ID="111">
<mango ID="333">
<colour>
<Rate_Structure_Event
ConceptType="Rate_Structure_Event"
ID="23b6128e-b622-4fa9-983b-95349bed5d41">
<Rate_Event
ConceptType="Rate_Event">
<Added_Unit_Rate>3000</Added_Unit_Rate>
</Rate_Event>
<Rate_Event
ConceptType="Rate_Event">
<Added_Unit_Rate>2000</Added_Unit_Rate>
</Rate_Event>
</Rate_Structure_Event>
</colour>
</mango>
<orange ID="222">
<color>orange</color>
</orange>
</fruit>
</tree>
However I get this output:
<tree>
<fruit ID="111">
<mango ID="333">
<Rate_Event ConceptType="Rate_Event">
<Added_Unit_Rate>3000</Added_Unit_Rate>
</Rate_Event>
<Rate_Event ConceptType="Rate_Event">
<Added_Unit_Rate>2000</Added_Unit_Rate>
</Rate_Event>
<colour>
<Rate_Structure_Event
ConceptType="Rate_Structure_Event"
ID="23b6128e-b622-4fa9-983b-95349bed5d41">
<Rate ConceptType="Rate_Event">
<Added_Unit_Rate>909000</Added_Unit_Rate>
</Rate>
<Rate ConceptType="Rate_Event">
<Added_Unit_Rate>909000</Added_Unit_Rate>
</Rate>
</Rate_Structure_Event>
</colour>
</mango>
<orange ID="222">
<color>orange</color>
</orange>
</fruit>
</tree>
Why are the elements copied outside the <colour>?
I think the problem lies in <xsl:copy-of
select="(key('step',string-join(ancestor-or-self::*[@ID]/@ID,',')),.)[*]
"/>
Any comments please?
Many Thanks,
Houman
|