Clemintine
Programmer
Hi,
Target : At any level where the text in @TITLE contains the searchterm 'Plate' select all child nodes of the found node and parent nodes of the found node, preserving the attributes.
There is a requirement to preserve the recursive quality of the current imperfect solution as the example xml is a much simpler version of the actual xml being used.
Problem : The XSL shown works perfectly well EXCEPT, when there is a parent AND child both containing the searchterm, the parents children that are siblings to the matching child don't show, somehow affected by the match on the child.
You can simulate this by altering the attribute TITLE in ITEM 'GM Crafted Female Plate' to 'GM Crafted Female'.
Top marks to any one who can answer this as I realise its not a simple one!
Sample XML:
<LINEDETAILS TITLE="Armour">
<EXPANSION TITLE="Shields">
<ITEM TITLE="GM Crafted Kite" PRICE="200"/>
<ITEM TITLE="GM Crafted Metal" PRICE="150"/>
<ITEM TITLE="GM Crafted Heater" PRICE="250"/>
<ITEM TITLE="GM Crafted Bronze" PRICE="150"/>
<ITEM TITLE="GM Crafted Small Kite" PRICE="150"/>
<ITEM TITLE="GM Crafted Buckler" PRICE="100"/>
</EXPANSION>
<EXPANSION TITLE="Helmets">
<ITEM TITLE="GM Crafted Bascinet" PRICE="150"/>
<ITEM TITLE="GM Crafted Nose Helm" PRICE="200"/>
<ITEM TITLE="GM Crafted Close Helm" PRICE="200"/>
<ITEM TITLE="GM Crafted Helm" PRICE="180"/>
<ITEM TITLE="GM Crafted Plate Helm" PRICE="400"/>
</EXPANSION>
<EXPANSION TITLE="Plate Mail">
<ITEM TITLE="GM Crafted Tunic" PRICE="1000"/>
<ITEM TITLE="GM Crafted Arms" PRICE="500"/>
<ITEM TITLE="GM Crafted Gloves" PRICE="350"/>
<ITEM TITLE="GM Crafted Gorget" PRICE="250"/>
<ITEM TITLE="GM Crafted Legs" PRICE="850"/>
<ITEM TITLE="GM Crafted Female Plate" PRICE="650"/>
</EXPANSION>
</LINEDETAILS>
XSL :
<xsl:stylesheet xmlns:xsl=" version="1.0" >
<xsl:template match="node()">
<xsl:choose>
<!-- if there are children with an TITLE attribute containing text 'Plate', copy node and recurse down the tree -->
<xsl:when test="descendant::node()[contains(@TITLE,'Plate')]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:when>
<!-- if there is an ancestor-or-self with a TITLE attribute containing text 'Plate', copy entire branch -->
<xsl:when test="contains(@TITLE,'Plate')">
<xsl:copy-of select="self::node()"/>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Kind Regards Clemintine!
Target : At any level where the text in @TITLE contains the searchterm 'Plate' select all child nodes of the found node and parent nodes of the found node, preserving the attributes.
There is a requirement to preserve the recursive quality of the current imperfect solution as the example xml is a much simpler version of the actual xml being used.
Problem : The XSL shown works perfectly well EXCEPT, when there is a parent AND child both containing the searchterm, the parents children that are siblings to the matching child don't show, somehow affected by the match on the child.
You can simulate this by altering the attribute TITLE in ITEM 'GM Crafted Female Plate' to 'GM Crafted Female'.
Top marks to any one who can answer this as I realise its not a simple one!
Sample XML:
<LINEDETAILS TITLE="Armour">
<EXPANSION TITLE="Shields">
<ITEM TITLE="GM Crafted Kite" PRICE="200"/>
<ITEM TITLE="GM Crafted Metal" PRICE="150"/>
<ITEM TITLE="GM Crafted Heater" PRICE="250"/>
<ITEM TITLE="GM Crafted Bronze" PRICE="150"/>
<ITEM TITLE="GM Crafted Small Kite" PRICE="150"/>
<ITEM TITLE="GM Crafted Buckler" PRICE="100"/>
</EXPANSION>
<EXPANSION TITLE="Helmets">
<ITEM TITLE="GM Crafted Bascinet" PRICE="150"/>
<ITEM TITLE="GM Crafted Nose Helm" PRICE="200"/>
<ITEM TITLE="GM Crafted Close Helm" PRICE="200"/>
<ITEM TITLE="GM Crafted Helm" PRICE="180"/>
<ITEM TITLE="GM Crafted Plate Helm" PRICE="400"/>
</EXPANSION>
<EXPANSION TITLE="Plate Mail">
<ITEM TITLE="GM Crafted Tunic" PRICE="1000"/>
<ITEM TITLE="GM Crafted Arms" PRICE="500"/>
<ITEM TITLE="GM Crafted Gloves" PRICE="350"/>
<ITEM TITLE="GM Crafted Gorget" PRICE="250"/>
<ITEM TITLE="GM Crafted Legs" PRICE="850"/>
<ITEM TITLE="GM Crafted Female Plate" PRICE="650"/>
</EXPANSION>
</LINEDETAILS>
XSL :
<xsl:stylesheet xmlns:xsl=" version="1.0" >
<xsl:template match="node()">
<xsl:choose>
<!-- if there are children with an TITLE attribute containing text 'Plate', copy node and recurse down the tree -->
<xsl:when test="descendant::node()[contains(@TITLE,'Plate')]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:when>
<!-- if there is an ancestor-or-self with a TITLE attribute containing text 'Plate', copy entire branch -->
<xsl:when test="contains(@TITLE,'Plate')">
<xsl:copy-of select="self::node()"/>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Kind Regards Clemintine!