This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Okay, so you can't do dynamic XPaths..


I'd like to come up with a generic stylesheet that can consume an XML 
document created by the Microsoft ADODB.Recordset.Save() function, and 
generate an appropriate HTML <select/> element.  Ideally, the stylesheet 
would contain parameters for specifiying which field should be used for the 
value, and which field should be used for the display.

I have come up with:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:rs="urn:schemas-microsoft-com:rowset"
  xmlns:z='#RowsetSchema'>

  <xsl:output method="html" encoding="ascii" omit-xml-declaration="yes" 
indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:param name="param-value-field"/>
  <xsl:param name="param-display-field"/>
  <xsl:param name="param-select-name"/>
  <xsl:param name="param-select-class"/>
  <xsl:param name="param-select-style"/>

  <xsl:template match="/">
    <select name="{$param-select-name}" class="{$param-select-class}" 
style="{$param-select-style}">
      <xsl:apply-templates select="/xml/rs:data"/>
    </select>
  </xsl:template>

  <xsl:template match="z:row">
    <option>
      <xsl:attribute name="value">
        <xsl:value-of select="@*[name() = $param-value-field]"/>
      </xsl:attribute>
      <xsl:value-of select="@*[name() = $param-display-field]"/>
    </option>
  </xsl:template>

</xsl:stylesheet>


The XML looks like this (most rows removed for brevity):

<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" 
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" 
xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
	<s:Schema id="RowsetSchema">
		<s:ElementType name="row" content="eltOnly" rs:CommandTimeout="30">
			<s:AttributeType name="SIC_CODE" rs:number="1">
				<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="8" 
rs:maybenull="false"/>
			</s:AttributeType>
			<s:AttributeType name="DESCRIPTION_100" rs:number="2" rs:nullable="true">
				<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="100"/>
			</s:AttributeType>
			<s:AttributeType name="LONG_DESC" rs:number="3" rs:nullable="true">
				<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="111"/>
			</s:AttributeType>
			<s:extends type="rs:rowbase"/>
		</s:ElementType>
	</s:Schema>
	<rs:data>
		<z:row SIC_CODE="00000" DESCRIPTION_100="Other" LONG_DESC="00000 - 
Other"/>
		<z:row SIC_CODE="00001" DESCRIPTION_100="Agricultural Prod - Crops" 
LONG_DESC="00001 - Agricultural Prod - Crops"/>
		<z:row SIC_CODE="00002" DESCRIPTION_100="Agricultural Prd - Livestockl" 
LONG_DESC="00002 - Agricultural Prd - Livestockl"/>
		<z:row SIC_CODE="00007" DESCRIPTION_100="Agricultural services" 
LONG_DESC="00007 - Agricultural services"/>
	</rs:data>
</xml>


Comments please?  The syntax:

select="@*[name() = $param-value-field]"/

strikes me as being somewhat ugly.  Is this the best I'm gonna get?

Many thanks,

Mike


_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]