Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a SELECT box in XSLT 1

Status
Not open for further replies.

KevinFSI

Programmer
Nov 17, 2000
582
US
Please forgive the fact that I am new to XML & XSLT, but I think my question will be simple.

I want my users to be able to edit the XML data stored in a file. I read the data in, and use XSLT to display the data in an HTML form. One of the options is "employee" which I want them to be able to select from a regular SELECT box based on a CFQUERY of our employee DB. How on earth do I do this?

Thanks!

 
If i undestand correctly you jus want know how to output a cf query result within your xslt. this is how I've done it in the past:

so you've run your query and have the result set then you need to create an xml document with the data in it

Code:
<!--- your query here somewhere --->

<cfxml variable="xmlDoc">
 <xsltData>
  <PeopleTypes>
   <cfoutput query="YourQuery">
    <Type>#YourQuery.YourFieldName#</Type>
   </cfoutput>
  </PeopleTypes>
 <xsltData>
</cfxml>

<!--- Now you have an xml document with the data from yur cfquery.  If you want to add other elements to this document you can, just make sure they are within the parent node (xsltData)  --->

<!--- xst file read --->
<cffile action="read" file="#ExpandPath()'.')#/your_xslt_file.xsl" variable="xslt">

<!--- transform them --->
<cfoutput>
#xmlTransform(xmlDoc, xslt)#
</cfoutput>

now your xslt file should look something like this:

Code:
<select name="whatever">
  <xsl:for-each select="/PeopleTypes/">
    <option value=""><xsl:value-of select="Type"/></option>
  </xsl:for-each>
</select>

I can never remember the full syntax for the xslt so if the above doesn't work let me know and I'll knock up a wrking xslt for you

Hope this helps!

Tony
 
The only question I have about this is that the xslt is for an XML document that already exists. I've used CFFILE to read in that doc, then xmlTransform() to apply the stylesheet. I was hoping there was a way I could mix the results of that query with the already existing XML doc.

 
there is, like this:

Code:
<!--- assuming that you have read your doc into vbl xmldoc --->

<!--- your query would go here --->

<!--- create a new vbl with the xml & query combined --->
<cfxml varibale="newXMLDoc">
  <NewDoc>
    <cfoutput>#variables.xlmdoc#</cfoutput>
    <PeopleTypes>
      <cfoutput query="YourQuery">
        <Type>#YourQuery.YourFieldName#</Type>
      </cfoutput>
    </PeopleTypes>
  </NewDoc>
</cfxml>

<!--- here is your new doc --->
<cfdump var="#newXMLDoc#">

<!--- do your transformation again here --->

Hope this helps!

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top