How can I process child nodes the same way as parent nodes using multiple files as input in XSLT?



I am currently trying to process multiple files for specific nodes and collect them in a meaningful way to demonstrate the parent-child relationship but I'm having trouble getting past the first level of children.


A little background:


I'm attempting to collect procedure codes from a service manual. The manual is composed of several XMLs. The procedures these codes refer to sometimes refer to subprocedures, which in turn may refer to subprocedures. I want to list out all the procedure codes. If there is a subprocedure referenced in a procedure, I want to list its code as a child and continue in this way for all subprocedure until a procedure is listed that does not include a subprocedure.


Something like this:



<service-manual>
<procedure>
<name>Procedure A</name>
<frt-num>1234</frt-num>
<child-proc>
<frt-num>2345</frt-num>
<child-proc>
<frt-num>3456</frt-num>
...
</child-proc>
<child-proc>
<frt-num>4567</frt-num>
...
</child-proc>
</child-proc>
...
</procedure>
...


However, the result that I'm getting from my style sheet is only processing the first set of children.


The style sheet I've developed looks like this:



<xsl:template match ="directory">
<service-manual>
<xsl:apply-templates select="file"/>
</service-manual>
</xsl:template >

<xsl:template match="file">
<xsl:variable name="path" select="@name"/>
<xsl:for-each select="document($path)/*">
<xsl:for-each select="/*">
<procedure>
<name>
<xsl:value-of select="title"/>
</name>
<frt-num>
<xsl:value-of select="substring-after(@id,'X')"/>
</frt-num>
<xsl:apply-templates select="//cmd"/>
</procedure>
</xsl:for-each>
</xsl:for-each>
</xsl:template>

<xsl:template match="//cmd">
<xsl:for-each select="xref">
<child-proc>
<frt-num>
<xsl:value-of select="substring-after(@keyref,'X')"/>
</frt-num>
<xsl:apply-templates select="file"/>
</child-proc>
</xsl:for-each>
</xsl:template>


Obviously, this is wrong. My thought was that I should create a template that processes the xref nodes and then call that template from the //cmd template but that didn't work much better. Is that the direction I should be taking with this? Also, is using modes an option here? Being that I'm a bit of an amateur, the logic involved with successfully accomplishing this has my brain twisted up a bit. Any help appreciated.


No comments:

Post a Comment