Results 1 to 7 of 7

Thread: [RESOLVED] Accessing another table from within xsl:for-each

  1. #1

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Resolved [RESOLVED] Accessing another table from within xsl:for-each


    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.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  2. #2
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    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.

  3. #3

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    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.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Accessing another table from within xsl:for-each

    What does your xml look like?

  5. #5

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    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>
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  6. #6
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    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>

  7. #7

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    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.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width