I am trying to process an xml file that has several different groups of states, such as
<root> <childgroup>16</childgroup> <setstate>init</setstate> <child1>...</child1> <child2>...</child2> <setstate>process<setstate> <child2>...</child2> <child3>...</child3> ..... <childgroup>17</childgroup> ...
I need to 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"> ...
code>
I did the simple part, which is going together and adding the chgrpno attribute and the stateid attribute to all the children (it makes a copy of all the elements except the child group and state, adding the attribute to these two.
<xsl:template match="/"> <xsl:apply-templates mode="numb"/> </xsl:template>
This works, and as a result, all the children have an attribute, so I could rearrange them in the next pass, and the states have numbers so that I can do the same later. 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 the changes that I made in the first pass disappeared. So what am I doing wrong here?
I am using XSLT 1.0 and not XSLT 2.0 explicitly.
(edit: of course, I named the variable, forgot to copy it).
source share