7.6 FileMaker Pro Value Lists and XSL
The FMPXMLRESULT with the -view action can return the value lists used for a field on a layout if you make an HTTP request. You can use the results to create a dynamic value list with XSL. The template will match the name of a list. The XML is shown below, followed by the XSL stylesheet to transform it into HTML.
Listing 7.10: Value list in XML
<VALUELIST NAME="list">
<VALUE>one</VALUE>
<VALUE>two</VALUE>
<VALUE>three</VALUE>
<VALUE>four</VALUE>
<VALUE>longword</VALUE>
<VALUE>five</VALUE>
<VALUE>six</VALUE>
<VALUE>longerwordhere</VALUE>
</VALUELIST>
Listing 7.11: XSL to use value list
<xsl:template match="fm:VALUELIST/@NAME=list">
<select name="myfield">
<option value="">-choose-</option>
<xsl:for-each select="fm:VALUE">
<option>
<xsl:attribute name="value">
<xsl:value-of select="." />
</xsl:attribute>
<xsl:value-of select="." />
</option>
</xsl:for-each>
</select>
</xsl:template>
Listing 7.12: HTML select list
<select name="myfield">
<option value="">-choose-</option>
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>
<option value="longword">longword</option>
<option value="five">five</option>
<option value="six">six</option>
<option value="longerwordhere">longerwordhere</option>
</select>
Listing 7.13: XSL to create check boxes
<xsl:template match="fm:VALUELIST/@NAME=list">
<xsl:for-each select="fm:VALUE">
<input type="checkbox" name="myfield" />
<xsl:attribute name="value">
<xsl:value-of select="." />
</xsl:attribute>
<xsl:text> </xsl:text>
<xsl:value-of select="." /><br />
</xsl:for-each>
</xsl:template>
You can create dynamic value lists based on the returned field contents, as well. For example, you may return a found set of records with FMPXMLRESULT and use the first field (fm:COL[1]) in each record (fm:ROW) as the value for the pop-up list, but the second field (fm:COL[2]) is the displayed text. Create your value list with XSL:
Listing 7.14: Value list with found set
<xsl:template match="fm:RESULTSET">
<select name="myfield">
<option value="">-choose-</option>
<xsl:for-each select="fm:ROW">
<option>
<xsl:attribute name="value">
<xsl:value-of select="fm:COL[1]" />
</xsl:attribute>
<xsl:value-of select="fm:COL[2]" />
</option>
</xsl:for-each>
</select>
</xsl:template>