RE: [xsl] Creating then using elements from xml table <row><entry > content?

Subject: RE: [xsl] Creating then using elements from xml table <row><entry > content?
From: "Kathy Burke" <Kathy_Burke@xxxxxxxxx>
Date: Wed, 29 Oct 2003 15:14:19 -0500
Thank you, Tom. Yes, I always overthink it! Also didn't get the RTF issue.

I appreciate your time.


-----Original Message-----
From: Passin, Tom [mailto:tpassin@xxxxxxxxxxxx]
Sent: Wednesday, October 29, 2003 2:31 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Creating then using elements from xml table
<row><entry> content?

[ Kathy Burke]

> With what I've tried so far, I don't get errors BUT I don't get output
> either!

If you do not get any output it is normally because your templates are
not getting invoked.

> My xml source (created using an xml authoring tool) contains 
> the following:
> <tools_materials>
> <table><tgroup cols="2">
> <?PubTbl tgroup dispwid="6.78in"?>
> <colspec colname="col1" colwidth="1.26*"/><colspec colname="col2"
> colwidth="0.74*"/>
> <tbody><row><entry>Tool/Material</entry>
> <entry>Part Number</entry></row>
> <row><entry>Operations Manual</entry><entry>092022-001</entry>
> </row><row><entry>Machine Management System</entry>
> <entry>10-MS30-1000-021</entry></row></tbody></tgroup></table>
> </tools_materials>
> In my stylesheet, I need to create parent/child elements from 
> the table
> content (excluding row 1), ex:
>    Column 1 = <tool_mat>Operations Manual
>    Column 2 =      <tool_partno>092022-001</tool_partno>
>                      </tool_mat>                 
> I then need to use those newly created elements in an html 
> table. 

No, I do not think that this is your task.  Anyway, you cannot do this
with standard xslt 1.0, because anything you "create" will be a result
tree fragment, not a node set.  You task is to get get the data of
certain entry elements into certain slots in the html table, is it not?

> I have the
> following xsl (the first template is just my feeble attempt):
> <xsl:template match="tools_materials/table">    <!-- just 
> trying to get the
> first element -->
> 	<xsl:for-each select="row[position() != 1]">
>                   <xsl:element name="tool_mat">
> 		<xsl:value-of
> select="normalize-space(cell[1])"/></xsl:element>
> 	</xsl:for-each>
> </xsl:template>

No need to make it hard.  If I understand what you want, just build it
up bit by bit, first the table, then the header row, then the rest of
the rows - something like this, although you will want to add some
details I have omitted (and I wrapped your source fragment in a "root"
element) -

<xsl:template match='/root'>
   <xsl:apply-templates select='tools_materials/table'/>

<xsl:template match="table">
      <xsl:apply-templates select='tgroup/tbody'/>

<xsl:template match='tbody'>
      <th><xsl:value-of select='row[1]/entry[1]'/></th>   
      <th><xsl:value-of select='row[1]/entry[2]'/></th>   
   <xsl:apply-templates select='row[position() > 1]'/>

<xsl:template match='row'>
      <td><xsl:value-of select='entry[1]'/></td>
      <td><xsl:value-of select='entry[2]'/></td>

See - clean and simple.  Now you can add the rest of the details that
make it look readable.  Don't fuss with widths, alignment, or background
colors until you have gotten the core of the thing working.


Tom P

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread