[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: XSLT transformation flow based upon data type (acc
Much thanks Jeni, Dion, Michael. I should have said XPath instead of XSLT (I always forget to separate XPath out of XSLT), but you guys seemed to steer me in the right direction anyway. The current project regulates MSXML (v4) parser so the MS extensions will work just fine in this case. I took a look at the XPath2.0wd and it does address extensive tie-in with schema. It looks like the xquery-typeof function is going to be similar to ms:type-local-name function? Jeni, you requested a write up for what I thought it should work... What I am making is a XSLT doc to handle "generic" XML docs reflecting a table structure looking something like: <NewDataSet> <Table1> <Data1>A</Data1> <Data2>B</Data2> <Data3>C</Data3> </Table1> <Table1> <Data1>D</Data1> <Data2>E</Data2> <Data3>F</Data3> </Table1> </NewDataSet> The XML docs will always have these 3 levels, and a proper schema validation, but the element names are subject to change. Different table, different data, and different amounts of data are possible. Rather than make one style sheet for every table, I'd much rather make one to serve most scenarios. Text, numbers and dates all need their own formatted HTML presentation. If i can get the type, then I can apply the proper formatting template and display most tables in one common format and manage the format from there. ============================ My first working version is: ============================ <xsl:template match="/"> <table> <xsl:apply-templates select="/*/*" /> </table> </xsl:template> <!-- match only those nodes having children having text --> <xsl:template match="*[*[text()]]"> <tr> <xsl:apply-templates select="*"/> </tr> </xsl:template> <xsl:template match="*[msxsl:type-local-name(.)='string']"> <td>str ~ <xsl:value-of select="."/></td> </xsl:template> <xsl:template match="*[msxsl:type-local-name(.)='dateTime']"> <td>date ~ <xsl:value-of select="."/></td> </xsl:template> <xsl:template match="*[msxsl:type-local-name(.)='unsignedByte']"> <td>unsignedByte ~ <xsl:value-of select="."/></td> </xsl:template> <xsl:template match="*"> <td>otherwise ~ <xsl:value-of select="."/></td> </xsl:template> ============================My second working version is: <xsl:template match="/"> <table> <xsl:apply-templates select="/*/*" /> </table> </xsl:template> <xsl:template match="*"> <tr> <xsl:for-each select="*"> <xsl:choose> <xsl:when test="msxsl:type-local-name(.)='string'"> <td>str ~ <xsl:value-of select="."/></td> </xsl:when> <xsl:when test="msxsl:type-local-name(.)='dateTime'"> <td>date ~ <xsl:value-of select="."/></td> </xsl:when> <xsl:when test="msxsl:type-local-name(.)='unsignedByte'"> <td>unsignedByte ~ <xsl:value-of select="."/></td> </xsl:when> <xsl:otherwise> <td>otherwise ~ <xsl:value-of select="."/></td> </xsl:otherwise> </xsl:choose> </xsl:for-each> </tr> </xsl:template> -----Original Message----- From: Michael Kay [mailto:michael.h.kay@xxxxxxxxxxxx] Sent: Saturday, October 19, 2002 2:22 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: XSLT transformation flow based upon data type (access schema from within XSLT?) > Note that XSLT 2.0 has much richer support for XML Schemas. > You may want to look at (e.g.) Kay's SAXON processor to see > if this meets your needs. Unfortunately Saxon doesn't yet implement this part of the spec. I've been waiting for (a) the spec to become more stable, and (b) a wider choice of schema tools to become available. I'm still having difficulty finding a tool that analyzes a schema statically and gives me API access to it. Anyone have any suggestions? Michael Kay Software AG home: Michael.H.Kay@xxxxxxxxxxxx work: Michael.Kay@xxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|