I. This transformation:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="text()"/>
<xsl:template match="model">
<xsl:apply-templates select=".." mode="gen">
<xsl:with-param name="pInclude" select="."/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="node()|@*" mode="gen">
<xsl:param name="pInclude" select="/.."/>
<xsl:copy>
<xsl:apply-templates mode="gen" select=
"node()[not(name()=name($pInclude)) or count(.|$pInclude)=1]|@*" >
<xsl:with-param name="pInclude" select="$pInclude"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
when applied on this XML document (the provided one with a third model
added and more than one Item
element):
<t>
<Item>
<stockcode>XXX1</stockcode>
<vehicle>Bentley</vehicle>
<model>Continental GT (2006-)</model>
<model>Continental Flying Spur (2006-)</model>
<model>Galactic Flying Spur (2006-)</model>
<width>9</width>
<wheel_size>20</wheel_size>
<offset>40</offset>
<bolt_pattermn>5x112</bolt_pattermn>
<brand>AEZ</brand>
<Velg_ID>AEZ Myta</Velg_ID>
<kit1>DK-ZJAE x1</kit1>
</Item>
<Item>
<stockcode>XXX1</stockcode>
<vehicle>Bentley</vehicle>
<model>XXX Continental GT (2006-)</model>
<model>YYY Continental Flying Spur (2006-)</model>
<model>ZZZ Galactic Flying Spur (2006-)</model>
<width>9</width>
<wheel_size>20</wheel_size>
<offset>40</offset>
<bolt_pattermn>5x112</bolt_pattermn>
<brand>AEZ</brand>
<Velg_ID>AEZ Myta</Velg_ID>
<kit1>DK-ZJAE x1</kit1>
</Item>
</t>
produces the wanted, correct result:
<Item>
<stockcode>XXX1</stockcode>
<vehicle>Bentley</vehicle>
<model>Continental GT (2006-)</model>
<width>9</width>
<wheel_size>20</wheel_size>
<offset>40</offset>
<bolt_pattermn>5x112</bolt_pattermn>
<brand>AEZ</brand>
<Velg_ID>AEZ Myta</Velg_ID>
<kit1>DK-ZJAE x1</kit1>
</Item>
<Item>
<stockcode>XXX1</stockcode>
<vehicle>Bentley</vehicle>
<model>Continental Flying Spur (2006-)</model>
<width>9</width>
<wheel_size>20</wheel_size>
<offset>40</offset>
<bolt_pattermn>5x112</bolt_pattermn>
<brand>AEZ</brand>
<Velg_ID>AEZ Myta</Velg_ID>
<kit1>DK-ZJAE x1</kit1>
</Item>
<Item>
<stockcode>XXX1</stockcode>
<vehicle>Bentley</vehicle>
<model>Galactic Flying Spur (2006-)</model>
<width>9</width>
<wheel_size>20</wheel_size>
<offset>40</offset>
<bolt_pattermn>5x112</bolt_pattermn>
<brand>AEZ</brand>
<Velg_ID>AEZ Myta</Velg_ID>
<kit1>DK-ZJAE x1</kit1>
</Item>
<Item>
<stockcode>XXX1</stockcode>
<vehicle>Bentley</vehicle>
<model>XXX Continental GT (2006-)</model>
<width>9</width>
<wheel_size>20</wheel_size>
<offset>40</offset>
<bolt_pattermn>5x112</bolt_pattermn>
<brand>AEZ</brand>
<Velg_ID>AEZ Myta</Velg_ID>
<kit1>DK-ZJAE x1</kit1>
</Item>
<Item>
<stockcode>XXX1</stockcode>
<vehicle>Bentley</vehicle>
<model>YYY Continental Flying Spur (2006-)</model>
<width>9</width>
<wheel_size>20</wheel_size>
<offset>40</offset>
<bolt_pattermn>5x112</bolt_pattermn>
<brand>AEZ</brand>
<Velg_ID>AEZ Myta</Velg_ID>
<kit1>DK-ZJAE x1</kit1>
</Item>
<Item>
<stockcode>XXX1</stockcode>
<vehicle>Bentley</vehicle>
<model>ZZZ Galactic Flying Spur (2006-)</model>
<width>9</width>
<wheel_size>20</wheel_size>
<offset>40</offset>
<bolt_pattermn>5x112</bolt_pattermn>
<brand>AEZ</brand>
<Velg_ID>AEZ Myta</Velg_ID>
<kit1>DK-ZJAE x1</kit1>
</Item>
II. A more generic, and still short transformation, where the element name on which to split is passed as an (external) parameter:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pName" select="'model'"/>
<xsl:template match="*">
<xsl:apply-templates select="parent::*[$pName = name(current())]" mode="gen">
<xsl:with-param name="pInclude" select="."/>
</xsl:apply-templates>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="node()|@*" mode="gen">
<xsl:param name="pInclude" select="/.."/>
<xsl:copy>
<xsl:apply-templates mode="gen" select=
"node()[not(name()=name($pInclude)) or count(.|$pInclude)=1]|@*" >
<xsl:with-param name="pInclude" select="$pInclude"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
III. The most generic solution to a generic problem of this kind:
See this answer: https://stackoverflow.com/a/8597577/36305