i not sure why applly-templates not work, have called template in xsl file searches element have answer "yes" continue template, that's ends cannot seem next template work. (using xslt 1.0)
example xml (this excerpt larger xml show point)
<properties> ... <bencut_1__1_ formula="">yes</bencut_1__1_> <ctrrad_1__2_ formula="">yes</ctrrad_1__2_> <cblrad_1__2_ formula="">yes</cblrad_1__2_> <cbrrad_1__2_ formula="">yes</cbrrad_1__2_> <ctlrad_1__2_ formula="">yes</ctlrad_1__2_> <cblrad_1__3_ formula="">yes</cblrad_1__3_> <cbrrad_1__3_ formula="">yes</cbrrad_1__3_> <ctlrad_1__3_ formula="">yes</ctlrad_1__3_> <ctrrad_1__3_ formula="">yes</ctrrad_1__3_> <bencut_1__2_ formula="">yes</bencut_1__2_> <bencut_2__1_ formula="">yes</bencut_2__1_> <bencuth_2__1_ formula="">21mm</bencuth_2__1_> <bencutw_2__1_ formula="">21mm</bencutw_2__1_> <bencutx_2__1_ formula="">21mm</bencutx_2__1_> <bencuty_2__1_ formula="">21mm</bencuty_2__1_> <benctr_2__1_ formula="">21mm</benctr_2__1_> <benctl_2__1_ formula="">21mm</benctl_2__1_> ... </properties>
firstly apply-templates search of "bencut_" or "bencut_" results data comes out different cases (that issue seperate problem).
<xsl:template match="properties" > <xsl:apply-templates select="*[contains(translate(name(),'bencut','bencut'),'bencut_')]" /> </xsl:template>
then need run next apply-templates of "bencut_" has value "yes", , find the end of string (the last 6 characters create matching string find other values in xml need extract group , present differently
<xsl:template match="*[contains(translate(name(),'bencut','bencut'),'bencut_')]" > <xsl:if test="text()='yes'"> <xsl:apply-templates select="following-sibling::*[contains(name(),substring(name(),string-length(name())-5))]" /> </xsl:if> </xsl:template>
this starts fail, because need check siblings of "bencut_" node contain same tail string , preceding or following (i removed original select of 'following-sibling::[contains(name(),substring(name(),string-length(name())-5))] | preceding-sibling::[contains(name(),substring(name(),string-length(name())-5)]' try , debug code)
[also unsure why "|" worked in situation when "and" not if has explanation that]
this final template going run going format each of other siblings found looked , presented like.
<xsl:template match="following-sibling::*[contains(name(),substring(name(),string-length(name())-5))]" > <xsl:value-of select="name()" /> </xsl:template>
the end result find matching tails "_1__2_" example , able see following data considering things ctrrad_1__2_ cutout top right radius.
cutout (1) section (2); top right radius - yes bottom left radius - yes cutout height - 21mm cutout width - 21mm ...
there 1-11 cutouts of 1-3 sections, ie 33 possible cutout blocks.
it's difficult understand problem is. first say:
it starts fail, because need check siblings of "bencut_" node contain same tail string , preceding or following
then say:
it's recognizing partial strings of template has me stumped,
try starting point:
xslt 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/properties"> <root> <xsl:apply-templates select="*[starts-with(translate(name(), 'bencut', 'bencut'), 'bencut_')][.='yes']" /> </root> </xsl:template> <xsl:template match="*[starts-with(translate(name(), 'bencut', 'bencut'), 'bencut_')]"> <xsl:variable name="key" select="substring(name(), string-length(name()) - 5)" /> <group key="{$key}"> <xsl:apply-templates select="../*[contains(name(), $key)]" mode="group"/> </group> </xsl:template> <xsl:template match="*" mode="group"> <xsl:copy-of select="." /> </xsl:template> </xsl:stylesheet>
applied input example, result be:
<?xml version="1.0" encoding="utf-8"?> <root> <group key="_1__1_"> <bencut_1__1_ formula="">yes</bencut_1__1_> </group> <group key="_1__2_"> <ctrrad_1__2_ formula="">yes</ctrrad_1__2_> <cblrad_1__2_ formula="">yes</cblrad_1__2_> <cbrrad_1__2_ formula="">yes</cbrrad_1__2_> <ctlrad_1__2_ formula="">yes</ctlrad_1__2_> <bencut_1__2_ formula="">yes</bencut_1__2_> </group> <group key="_2__1_"> <bencut_2__1_ formula="">yes</bencut_2__1_> <bencuth_2__1_ formula="">21mm</bencuth_2__1_> <bencutw_2__1_ formula="">21mm</bencutw_2__1_> <bencutx_2__1_ formula="">21mm</bencutx_2__1_> <bencuty_2__1_ formula="">21mm</bencuty_2__1_> <benctr_2__1_ formula="">21mm</benctr_2__1_> <benctl_2__1_ formula="">21mm</benctl_2__1_> </group> </root>
p.s.
a more efficient version use key:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:key name="elem-by-tail" match="*" use="substring(name(), string-length(name()) - 5)" /> <xsl:template match="/properties"> <root> <xsl:apply-templates select="*[starts-with(translate(name(), 'bencut', 'bencut'), 'bencut_')][.='yes']" /> </root> </xsl:template> <xsl:template match="*[starts-with(translate(name(), 'bencut', 'bencut'), 'bencut_')]"> <xsl:variable name="key" select="substring(name(), string-length(name()) - 5)" /> <group key="{$key}"> <xsl:apply-templates select="key('elem-by-tail', $key)" mode="group"/> </group> </xsl:template> <xsl:template match="*" mode="group"> <xsl:copy-of select="." /> </xsl:template> </xsl:stylesheet>