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 TouchToneTommy 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 control 1

Status
Not open for further replies.

Kalisto

Programmer
Feb 18, 2003
997
GB
In my xsd I have a set of enumerated types within an element. Is there any way of extracting these and inserting them into my xslt via xpath, or do I need to either;
1) code them in an includable xml file
2) Hard code them in the xslt, which means I have 3 duplicate sets of data (database, xslt and xsd) to maintain and synchronise

K
 
How about:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]
  <xsl:template match="/">
    <select name="myselect">
      <xsl:for-each select="document('myschema.xsd')/xs:schema/xs:element[@name='myelement']//xs:enumeration">
        <option value="{@value}">
          <xsl:value-of select="@value"/>
        </option>
      </xsl:for-each>
    </select>
  </xsl:template>
</xsl:stylesheet>
 
Thanks. It doesnt quite work yet (the list doesnt populate, but the page renders an empty select control, so Im guessing I have a type somewhere.

Whilst I remember, thanks for trying to help me yesterday, it was the tools I was using misbehaving, not the code in the end.

K
 
The XPath is probably incorrect for your schema. Is the namespace prefix correct? Do you have the correct path to the schema? Posting your schema (or portion of) will help.
 
Its sorted ta, one of the elements (the one I was testing with obviously) was defined as a sub element of an element, i.e. <element><stuff><element><enum values></element></element>

To make it easier and save asking again, I made the internal element a ref and extracted it to an element all of its own, and it now works.

Thanks anyway!
 
You could've just changed the XPath:

document('myschema.xsd')/xs:schema//xs:element[@name='myelement']//xs:enumeration
 
Dmanit, I tried everything I could think of except the double \\ before the element! Thanks, I need to buy a book I think.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top