Recursion Question

wxdqz

New Member
I am trying to use XSLT to convert an XML file and am having problems w/ recursion. The XML file looks like this:

<root>
<detail>
<123>
<COORD>123456.123N1234567.890E</COORD>
<COORD_DERIV_ACC>1.234 </COORD_DERIV_ACC>
<COORD_DERIV_ACC_UM>NM</COORD_DERIV_ACC_UM>
<COORD_DERIV_ACC_CONF_LVL>90</COORD_DERIV_ACC_CONF_LVL>
<ELEVATION>1650.721 </ELEVATION>
<ELEVATION_UM>M</ELEVATION_UM>
<ELEVATION_DERIV_ACC>2.345 </ELEVATION_DERIV_ACC>
<ELEVATION_DERIV_ACC_UM>M</ELEVATION_DERIV_ACC_UM>
<ELEVATION_CONF_LVL>90</ELEVATION_CONF_LVL>
<TGT_DTL_NAME>11</TGT_DTL_NAME>
</123>
<ABC>
<imagePoints>
<image id="img1" />
<image id="img2" />
</imagePoints>
<elevationSource>ElevationSource</elevationSource>
</ABC>
</detail>

<detail>
...
</detail>
</root>

Basically, for each "detail, my code is returning a list of the first image id for each record. In other words, if there are 10 records (details), each w/ 2 image ids, then each record returns 10 image ids for "img1". 搃mg2?does not show up. What I really need is for each detail to contain one variable of concatenated image ids for that detail and seperated by a space (i.e., 搃mg1 img2?. Here is my XSL code. I believe the problem is in the "combine-images" template, probably in the xsl:if statement:

<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" indent="yes" />

<xsl:template match="/">
<xsl:apply-templates select="//detail" />
</xsl:template>

<xsl:template match="detail">
<table width="850" border="0" cellpadding="5" cellspacing="0">
<tr>
<xsl:for-each select="123">
<td><xsl:value-of select="TGT_DTL_NAME" /></td>

<xsl:variable name="coord" select="COORD" />
<xsl:choose> <!-- North or South? -->
<xsl:when test="contains($coord,&apos;N&apos;)">
<xsl:variable name="lat" select="concat(substring($coord,1,6), '.', substring($coord,7,3), ' N')" />
<td><xsl:value-of select="$lat" /></td>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="lat" select="concat(substring($coord,1,6), '.', substring($coord,7,3), ' S')" />
<td><xsl:value-of select="$lat" /></td>
</xsl:otherwise>
</xsl:choose>
<xsl:choose> <!-- East or West? -->
<xsl:when test="contains($coord,&apos;E&apos;)">
<xsl:variable name="lon" select="concat(substring($coord,11,7), '.', substring($coord,18,3), ' E')" />
<td><xsl:value-of select="$lon" /></td>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="lon" select="concat(substring($coord,11,7), '.', substring($coord,18,3), ' W')" />
<td><xsl:value-of select="$lon" /></td>
</xsl:otherwise>
</xsl:choose>

<td><xsl:value-of select="ELEVATION" /></td>
<td><xsl:value-of select="COORD_DERIV_ACC" /></td>
<td><xsl:value-of select="ELEVATION_DERIV_ACC" /></td>

<xsl:call-template name="combine-images">
<xsl:with-param name="imgids" select="//image" />
</xsl:call-template>

</xsl:for-each>

</tr>
</table>
</xsl:template>

<xsl:template name="combine-images">
<xsl:param name="imgids" select="empty" />
<xsl:variable name="first-node" select="$imgids[1]" />
<xsl:variable name="rest" select="$imgids[position()!=1]" />
<td><xsl:value-of select="$first-node/@id" />
<xsl:text> </xsl:text>

<xsl:if test="$rest">
<xsl:call-template name="combine-images">
<xsl:with-param name="imgids" select="$rest" />
</xsl:call-template>
</xsl:if>
</td>
</xsl:template>

</xsl:stylesheet>



Any help would be greatly appreciated. The end result of this exercise is to eventually replace the <td> elements w/ tabs and save output to a tab-delimited text file. Thanks in advance.

Ken
 
Back
Top