[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] how to pass parameters down through nested templates using xsl:apply templates in a nested fashion?


Subject: RE: [xsl] how to pass parameters down through nested templates using xsl:apply templates in a nested fashion?
From: "SANWAL, ABHISHEK (HP-Houston)" <abhishek.sanwal@xxxxxx>
Date: Wed, 10 Sep 2003 17:31:24 -0500

Wendell,

Just made the changes you suggested. But still have an issue.
Please correct the following if they are wrong.

To push the initial value of the parameter - (Okay or not)
<xsl:with-param name="HeadAlign" select="'Center'"/>
<xsl:with-param name="DataAlign" select="'Left'"/>

To obtain the parameter value in the called template  (with default
values)
<xsl:param name="HeadAlign" select="'Right'"/>

Its just a literal string that I want to place in the <th>, <td> or <tr>
tags to set the text alignment of the cell. Like this... (doesn't work)
To push the value of the parameter out.
(Should I use XSL"value of and how would I actually write it into the
the following HTML tags ??

	<tr align="$HeadAlign">
	<th align="$HeadAlign">
	<td align="$DataAlign">

Unfortunately it wont "spit" out those parameters into the th, tr, td
values. I have tried this with curly braces and without and etc.

Of course I am getting nowhere with the trial and error.

Please let me know what would be the correct "syntax" for the THREE XSL
statements as mentioned above. (to make this possible :( ).

Thanks a lot.

Abhishek Sanwal



ENTIRE NEW CODE ATTACHED BELOW:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:template match="Matrix">
<xsl:param name="HeadAlign" select="'Right'"/>
<xsl:param name="DataAlign" select="'Right'"/>

	<xsl:if test="contains(@HeadFlow,'H')">
		<font class="debug">Horizontal</font>		

		<table border="0">
			<xsl:apply-templates mode="H">
			<xsl:with-param name="HeadAlign"
select="'Center'"/>
			<xsl:with-param name="DataAlign"
select="'Center'"/>
			</xsl:apply-templates>
		</table>
	</xsl:if>

	<xsl:if test="contains(@HeadFlow,'V')">
		<font class="debug">Vertical</font>

		
		<table border="0">
			<xsl:apply-templates mode="V">
			<xsl:with-param name="HeadAlign"
select="'Left'"/>
			<xsl:with-param name="DataAlign"
select="'Left'"/>
			</xsl:apply-templates>
		</table>
	</xsl:if>

</xsl:template>

<xsl:template match="MatrixHeadArray" mode="H">
<xsl:param name="HeadAlign" select="'Right'"/>
<xsl:param name="DataAlign" select="'Right'"/>
	<tr align="$HeadAlign">
		<xsl:apply-templates mode="H">
		<xsl:with-param name="HeadAlign" select="$HeadAlign"/>
		<xsl:with-param name="DataAlign" select="$DataAlign"/>
		</xsl:apply-templates>
	</tr>
</xsl:template>

<xsl:template match="MatrixHeadCell" mode="H">
<xsl:param name="HeadAlign" select="'Right'"/>
<xsl:param name="DataAlign" select="'Right'"/>
	<th align="$HeadAlign">
		<xsl:apply-templates/>
	</th>
</xsl:template>

<xsl:template match="MatrixDataArray" mode="H">
<xsl:param name="HeadAlign" select="'Right'"/>
<xsl:param name="DataAlign" select="'Right'"/>
	<tr align="$DataAlign">
		<xsl:apply-templates mode="H">
		<xsl:with-param name="HeadAlign" select="$HeadAlign"/>
		<xsl:with-param name="DataAlign" select="$DataAlign"/>
		</xsl:apply-templates>
	</tr>
</xsl:template>

<xsl:template match="MatrixDataCell" mode="H">
<xsl:param name="HeadAlign" select="'Right'"/>
<xsl:param name="DataAlign" select="'Right'"/>
	<td align="$DataAlign">
		<xsl:apply-templates/>
	</td>
</xsl:template>

<xsl:template match="MatrixHeadArray" mode="V">
<xsl:param name="HeadAlign" select="'Right'"/>
<xsl:param name="DataAlign" select="'Right'"/>
	<xsl:for-each select="MatrixHeadCell">
		<tr>
			<th align="{$HeadAlign}">
				<xsl:apply-templates/>
			</th>
			<xsl:variable name="headloc">
				<xsl:value-of select="@i"/>
			</xsl:variable>
			<xsl:for-each select="../../MatrixDataArray">
				<td align="{$DataAlign}">
					<xsl:apply-templates
select="MatrixDataCell[@i=$headloc]"/>
				</td>
			</xsl:for-each>
		</tr>
	</xsl:for-each>
</xsl:template>

<xsl:template match="MatrixDataCell" mode="V"/>
<xsl:param name="HeadAlign" select="'Right'"/>
<xsl:param name="DataAlign" select="'Right'"/>

</xsl:stylesheet>


Abhishek Sanwal
HP - Houston Campus
abhishek.sanwal@xxxxxx
(O): +1-281-518-4707
(M): +1-469-569-4605
 

-----Original Message-----
From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx] 
Sent: Wednesday, September 10, 2003 4:38 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] how to pass parameters down through nested templates
using xsl:apply templates in a nested fashion?

Abhishek,

At 05:08 PM 9/10/2003, you wrote:
>At the first instance it sees this
>"<xsl:with-param name="HeadAlign" select="{$HeadAlign}"/>"
>It says
>"Invalid XPath Expression"

Yes, that'll break. Correct would be select="$HeadAlign".

>While this works:
><xsl:with-param name="HeadAlign" select="Left"/>

"Left" is a valid XPath expression: it's short for child::Left (element 
children of the context node named "Left"). That might not be what you
mean 
it to be, but it won't throw an error, either.

To bind the string literal "Left" to the parameter, use select="'Left'".

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
   Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords