[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

Subject: Okay, so you can't do dynamic XPaths..
From: "Michael Peet" <mjpeet@xxxxxxxxxxx>
Date: Fri, 17 May 2002 18:14:09 -0400
adodb.recordset.save
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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.