[RESOLVED] Accessing another table from within xsl:for-each
:wave:
I'm very new to xsl. I have this xsl file where I'm looping through the rows in an xml data table using a for-each and placing the field values into html. One of the field values in the xml table, however, needs to be translated using another xml table. How do I query the other table from within the for-each using the value from my field in the for-each to return the appropriate value from the other table?
Is this making any sense? Any help would be appreciated.
Re: Accessing another table from within xsl:for-each
I would expect forum members to respond to your question quickly if they can read a piece of your code. Describing the problem alone is not enough to get a quick response.
Re: Accessing another table from within xsl:for-each
Maybe this will help you understand better. Here's the snipped from the xsl file:
Code:
<table border='1' width='100%'>
<col width="15%" />
<col width="35%" />
<col width="15%" />
<col width="35%" />
<xsl:for-each select ='NewDataSet/FACILITY_INFO'>
<tr>
<td>Facility Number</td><td><xsl:value-of select='FACILITY_NUMBER'/></td>
<td>Layer Name</td><td><xsl:value-of select ='LAYER_ID'/></td>
</tr>
<tr>
<td>Description</td><td><xsl:value-of select='FACILITY_DESC'/></td>
<td>Facility ID</td><td><xsl:value-of select ='SDS_ID'/></td>
</tr>
</xsl:for-each>
</table>
The value that reads 'LAYER_ID' is what I need to use to reference the 'map_layer' table to pull out the 'layer_name'. The layer_name is what actually needs to be displayed in that table cell.
Re: Accessing another table from within xsl:for-each
What does your xml look like?
Re: Accessing another table from within xsl:for-each
Here's an example of the xml (the whole file is about 1.5 megs).
Code:
<NewDataSet>
<FACILITY_INFO>
<FACILITY_OID>384</FACILITY_OID>
<INSTALLATION_ID>1000</INSTALLATION_ID>
<LAYER_ID>13</LAYER_ID>
<SDS_ID>Bldg_AGM_1010</SDS_ID>
<RPU_ID />
<FACILITY_TIER>0</FACILITY_TIER>
<FACILITY_ACTIVE>true</FACILITY_ACTIVE>
<GLOC>none</GLOC>
<FACILITY_NUMBER>1010</FACILITY_NUMBER>
<FACILITY_DESC>Ammo Struc Inst</FACILITY_DESC>
<FACILITY_NAME>Ammo Struc Inst</FACILITY_NAME>
<LOCATION>here</LOCATION>
<TYPE_CODE>AGM</TYPE_CODE>
<SUB_CATEGORY_CODE>42142</SUB_CATEGORY_CODE>
<TYPE_CODE_JUSTIFICATION>RPI Import</TYPE_CODE_JUSTIFICATION>
<SUB_CAT_CODE_JUSTIFICATION>RPI Import</SUB_CAT_CODE_JUSTIFICATION>
<OWNER>NFESC</OWNER>
<USING_ORGANIZATION>ESS</USING_ORGANIZATION>
<DRAWING_NUMBER>123</DRAWING_NUMBER>
<LICENSE>456</LICENSE>
<FACILITY_COST>200000</FACILITY_COST>
<OCCUPANTS_MIL>2</OCCUPANTS_MIL>
<REQUIRES_SA>0</REQUIRES_SA>
<EVAL_ZONE_DISTANCE>873.070556640625</EVAL_ZONE_DISTANCE>
<SEARCH_ZONE_DISTANCE>3969</SEARCH_ZONE_DISTANCE>
<LAST_MODIFIED_DATE>2012-08-29T19:06:04.865-04:00</LAST_MODIFIED_DATE>
</FACILITY_INFO>
<MAP_LAYER>
<LAYER_ID>13</LAYER_ID>
<LAYER_NAME>Structure_Existing_Site</LAYER_NAME>
</MAP_LAYER>
</NewDataSet>
Re: Accessing another table from within xsl:for-each
There are probably better ways to select the proper map layer node but this should work
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<table border='1' width='100%'>
<col width="15%" />
<col width="35%" />
<col width="15%" />
<col width="35%" />
<xsl:for-each select ='NewDataSet/FACILITY_INFO'>
<tr>
<td>Facility Number</td>
<td>
<xsl:value-of select='FACILITY_NUMBER'/>
</td>
<td>Layer Name</td>
<td>
<xsl:call-template name='maplayer'>
<xsl:with-param name='layerId'>
<xsl:value-of select ='LAYER_ID'/>
</xsl:with-param>
</xsl:call-template>
</td>
</tr>
<tr>
<td>Description</td>
<td>
<xsl:value-of select='FACILITY_DESC'/>
</td>
<td>Facility ID</td>
<td>
<xsl:value-of select ='SDS_ID'/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template name='maplayer'>
<xsl:param name='layerId' />
<xsl:for-each select='//MAP_LAYER'>
<xsl:if test='LAYER_ID = $layerId'>
<xsl:value-of select ='LAYER_NAME' />
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Re: Accessing another table from within xsl:for-each
Thanks! I was having trouble understanding how to pass parameters to templates. This should get me going in the right direction.