RE: [xsl] Include States

Subject: RE: [xsl] Include States
From: "Martinez, Brian" <brian.martinez@xxxxxxxxxxx>
Date: Wed, 16 Apr 2003 09:47:26 -0600
> From: Karl J. Stubsjoen [mailto:karl@xxxxxxxxxxxxx]
> Sent: Wednesday, April 16, 2003 9:26 AM
> Subject: [xsl] Include States
> 
> 
> Hello,
> I know how to import a stylesheet into my stylesheet.  What I 
> need to do is
> import XML into my style sheet.
> The XML is a list of states, full text and abbreviation.
> Actually, If I could import a stylesheet responsible for 
> trnasforming the
> state xml file into an HTML select widget, this would be 
> good.  But, can
> that stylesheet then import the XML?

Use the document() function.

Example XML:

<states>
  <state abbr="AL">Alabama</state>
  <state abbr="AR">Arkansas</state>
  <!-- etc. -->
</states>

XSLT (not meant to be standalone output):

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="html"/>

  <xsl:variable name="state-xml" select="document('states.xml')/states"/>  

  <xsl:template match="/">
    <select name="states-dropdown">
      <xsl:for-each select="$state-xml/state">
        <option value="{@abbr}"><xsl:value-of select="."/></option>
      </xsl:for-each>
    </select>
  </xsl:template>
</xsl:stylesheet>

Output:

<select name="states-dropdown">
  <option value="AL">Alabama</option>
  <option value="AR">Arkansas</option>
</select>

hth,
b.

| brian martinez                           brian.martinez@xxxxxxxxxxx |
| lead gui programmer                                    303.708.7248 |
| cheap tickets, part of trip network                fax 303.790.9350 |
| 6436 s. racine cir.                             englewood, co 80111 |
| cendant travel distribution services   http://www.cheaptickets.com/ |

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread