xsl-list
[Top] [All Lists]

RE: Include States

2003-04-16 08:47:26
From: Karl J. Stubsjoen [mailto:karl(_at_)azprogolf(_dot_)com]
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="{(_at_)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(_dot_)martinez(_at_)cendant(_dot_)com |
| 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



<Prev in Thread] Current Thread [Next in Thread>