Search

XSLT help needed

In XQuery I can write generic code like this function to convert an html table to XML  - well some of them - this doesn't handle thead and tbody and the conversion of strings to XML names is rubbish but you get the picture.

However although I can write XSLT for ordinary transformations, I'm just not sure about how to code this in  XSLT

declare function local:table2xml($table) {
   let $header :=($table/*:tr)[1]
   let $names := for $col in $header/(*:td,*:th) return replace($col,"[  %]","")
   return
       element table {
          for $row in subsequence ($table/*:tr, 2)
          return
            element row {
               for $col at $i in $names
               let $data := data($row/(*:td,*:th)[$i])
               return 
                  element {$col}  {$data}
            }
     }
};


I'd welcome a helping hand here - anyone?

<xsl:stylesheet>
<xsl:template>

<xsl:variable />
<xsl:for-each>
<row>
<xsl:for-each>
<xsl:variable />
<xsl:element><xsl:value-of /></xsl:element>
</xsl:for-each>
</row>
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>
Attributes not rendered ?!?!!

< xsl:stylesheet xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" exclude-result-prefixes="xhtml" >
< xsl:template match="xhtml:table" >
< table xmlns="" >
< xsl:variable name="headers" select="xhtml:tr[1]" />
< xsl:for-each select="xhtml:tr[position() > 1]" >
< row >
< xsl:for-each select="xhtml:td" >
< xsl:variable name="pos" select="position()" />
< xsl:element name="{$headers/xhtml:td[position() = $pos]}" >< xsl:value-of select="." />< /xsl:element >
< /xsl:for-each >
< /row >
< /xsl:for-each >
< /table >
< /xsl:template >
< /xsl:stylesheet >