This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

acessing attribute values and adding them to a param, looping


Hello!

I have a XML like this:



--- snip ---

<table cols-id="5">

	<tr>
		<td><content key="string" number="3" /></td>
		<td><design key="vruler" /></td>
		<td><content key="string" number="4" /></td>
		<td><content key="string" number="5" /></td>
		<td><content key="string" number="6" /></td>
	</tr>

--- snip ---



My XSL should produce an HTML table row for an input <tr> element and it
looks like this at the moment:


--- snip ---
<xsl:template name="insertspacer">
	<xsl:comment>Spacer row generated</xsl:comment>
	<tr>
		<xsl:call-template name="loopspacer">
			<xsl:with-param name="i">1</xsl:with-param>
		</xsl:call-template>
		
		<td bgcolor="#4E4D49" width="1" height="1"><img
src="img/trans.gif" width="1" height="1" border="0"/></td>
		<td width="10" height="1"
background="img/schatten_re.gif"><img src="img/trans.gif" width="10"
height="1" border="0"/></td>
	</tr>
</xsl:template>	
	

<xsl:template name="loopspacer">
	<xsl:param name="i" />
	<xsl:if test="number($i) &lt; $cols-id">
			<td>
				<xsl:attribute
name="width">1</xsl:attribute>
				<xsl:attribute
name="height">10</xsl:attribute>		
				<xsl:if
test="parent::table/child::tr[position() = 1]/child::td[position() =
$i]/child::design[attribute::key = 'vruler']">
					<xsl:attribute
name="bgcolor">#4E4D49</xsl:attribute>
				</xsl:if>
				<img src="img/trans.gif" width="1"
height="1" border="0"/>
			</td>
			<td width="5" height="1"><img src="img/trans.gif"
width="5" height="1" border="0"/></td>
			<td width="1" height="1"><img src="img/trans.gif"
width="1" height="1" border="0"/></td>
			<td width="5" height="1"><img src="img/trans.gif"
width="5" height="1" border="0"/></td>
		<xsl:call-template name="loopspacer">
			<xsl:with-param name="i" select="number($i) + 1" />
		</xsl:call-template>
	</xsl:if>
</xsl:template>
--- snip ---




That means the template insertspacer is called and generates two <td>
elements within a <tr> framework and calls the loopspacer template with the
param i initialized with the value "1". $cols-id is a top-level variable
that gets initialized with the maximum number of <td> children of a <tr> in
the input XML, here with the value "5". loopspacer is called recursively
($cols-id -1) times and outputs 4 <td> elements in each iteration.
Now the tricky thing is that if an input <td> has a <design> child with an
attribute key, value "vruler", a bgcolor attribute should be set for an
output <td> and only then. The code above works fine till here.

Now take a look at the following input XML and watch the colspan attributes:


--- snip ---

<table cols-id="5">
	<tr>
		<td colspan="2"><content key="string" number="1" /></td>
		<td><design key="vruler" /></td>
		<td colspan="2"><content key="string" number="2" /></td>
	</tr>

--- snip ---




Here the second <td> element has already a <design> child, but virtually it
is the third one. My XSL now recognizes the second <td> as the special one
an sets the bgcolor attribute for the output already in the second
iteration, not in the third like it should. Hope you see the problem.



What I already tried is to define a second param, called j that gets
initialized with value "1" and incremented depending on the colspan value of
an input <td>. So I could have two params, i that gets incremented with +1
for each iteration and j that gets incremented with +1 if the input <td> has
no colspan attribute, otherwise with +n where n is the value of the colspan
attribute. Doing this I should be able to change the condition for the
bgcolor attribute and assign it correctly. But how to arrange that?


--- snip inside loopspacer template ---

<xsl:choose>
	<xsl:when test="parent::table/child::tr[position() =
1]/child::td[position() = $i][attribute::colspan]">
		<xsl:variable name="colspanadd"
select="parent::table/child::tr[position() = 1]/child::td[position() =
$i]/@colspan" />
	</xsl:when>
	<xsl:otherwise>
		<xsl:variable name="colspanadd">1</xsl:variable>
	</xsl:otherwise>
</xsl:choose>


<xsl:call-template name="loopspacer">
	<xsl:with-param name="i" select="number($i) + 1" />
	<xsl:with-param name="j" select="number($j) + $colspanadd" />
</xsl:call-template>

--- snip ---


But I get a variable reference error that is obvious. It was only for
imagination.



Any ideas would help me a lot!



Thanks

Sebastian Schirmer
Softwareentwicklung

<<<<<<<<<<<<<<<<<<<<<<<<<<<
<sitewaerts> GmbH
Hebelstr. 15
76133 Karlsruhe
Germany

Tel.:  	+49 (721) 920 918 28
Fax:  	+49 (721) 920 918 29
Mobil:	+49 (177) 6 57 44 20

mailto:schirmer@sitewaerts.de
http://www.sitewaerts.de
>>>>>>>>>>>>>>>>>>>>>>>>>>>

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]