Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT: Table parts in multiple templates

Status
Not open for further replies.

thenewa2x

Programmer
Dec 10, 2002
349
US
Hi,

I need to be able to begin a table in one template and end it in another.

I would do all of the table stuff in a single template but a special editor called Serna does not handle templates like this very well.

So is having a table (table, row, and cell) broken out into several templates possible?

I know you can have an entire table in one, an entire row in another, and an entire cell in another but that is not what I want.

---------------------------------------
TINSTAAFL, which is why I contribute.
 
>So is having a table (table, row, and cell) broken out into several templates possible?
Not if that means <table> or <tr> or <td> open in one template and then somewhere </table> or </tr> or </td> in another template. Reason? It won't be well-formed xsl document. And I don't see any reason to having such kind of breakup.

>I would do all of the table stuff in a single template but a special editor called Serna does not handle templates like this very well.
One usually do this to assemble the complete table in parts. Off-hand and figuratively, I can sketch a case like this to illustrate it.
[tt]
<xsl:template match="x">
<table>
<xsl:apply-templates select="y|z">
</table>
</xsl:template>
<xsl:template match="y">
<tr>
<xsl:for-each select="./*">
<td><xsl:value-of select="." /></td> <!-- or whatever -->
</xsl:for-each>
</tr>
</xsl:template>
<xsl:template match="z">
<tr>
<xsl:apply-templates select="./*" />
</tr>
</xsl:template>
<xsl:template match="a"> <!-- suppose sequence of a under z -->
<td><xsl:value-of select="." /></td>
</xsl:template>
[/tt]
Each and every <table>, <tr> or <td> close within a template. If breaking up does not work correctly, you might have done it wrong. If combined in one template does not work, you too might have done something wrong. Serna or whatever may most probably be innocent.
 
Thanks tsuji but that's exactly what I did not want.

I would like to use that but the templates are not based on the structure of an XML document. Rather they are called upon by name when they are needed. This is because I am making a table structure that is abstract and can be used in multiple stylesheets. If I used the broken out method, I would have cells and rows outside of the table.

 
thenewa2x said:
but the templates are not based on the structure of an XML document
This is a contradiction in terms. Templates act upon XML documents and are themselves part of an XML document, and have to obey the rules of XML.

Since tsuji's post is correct, either you want what cannot be achieved (which I doubt) or you have to explain the problem adequately.

Can you create a somewhat simplified input document, and also show the desired output of the transformation upon that document? That may be the simplest way to allow us to provide accurate help.

Tom Morrison
 
I'm not really good at conveying what I need, my apologies.

I will seek an alternative way to accomplish what I need. I don't think my current path is very practical.

 
me said:
Can you create a somewhat simplified input document, and also show the desired output of the transformation upon that document?
If you have an XML document as input, and need (X)HTML as output, you should be able to do what you need using XSLT. As my boss says, "XSLT can do anything!" While I may not go quite that far, XSLT is an extremely powerful technology.

thenewa2x said:
I don't think my current path is very practical.
Perhaps not, but we really don't know what your problem is yet. All we know is that a particular solution path that you have attempted is not working, due to the constraints of XML.
thenewa2x said:
I will seek an alternative way to accomplish what I need.
That is what I am proposing, but still within the realm of XSLT.

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top