I am trying to process an xml file which has several different state groups like
<root>
<childgroup>16</childgroup>
<setstate>init</setstate>
<child1>...</child1>
<child2>...</child2>
<setstate>process<setstate>
<child2>...</child2>
<child3>...</child3>
.....
<childgroup>17</childgroup>
...
What I need is actually get something like
<childgroup no="16">
<state statename="init">
<child1>...</child1>
<child2>...</child2>
</state>
<state statename="process">
<child2>...</child2>
<child3>...</child3>
</state>
</childgroup>
<childgroup no="17">
...
I’ve done simple part which is going and adding “chgrpno” attribute and stateid attribute to all childs (it makes copy-of of all elements but childgroup and state, adding the attribute to those two.
<xsl:template match="/">
<xsl:apply-templates mode="numb"/>
</xsl:template>
This works and in the result all childs have attribute so I could regroup them in the next pass and states have numbers so I could later make same thing. But trying to follow the example of M.Kay with “temporary documents” when I try to do
<xsl:variable name="nmb">
<xsl:apply-templates mode="numb"/>
</xsl:variable>
<xsl:template match="/">
<xsl:copy-of select="$nmb"/>
</xsl:template>
then it just returns the original to me, and all changes which I made in the first pass are gone. So what am I doing wrong here?
I use XSLT 1.0, not XSLT 2.0 explicitly.
(edit: surely I named the variable, forgot to copy it here).
Here is an example how to approach the grouping with XSLT 1.0 in one step; the stylesheet
transforms the input sample
into