You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by in...@gmx.de on 2002/07/22 11:36:38 UTC
use of variables in xsl:value-of
Hello,
I have problems with the use of variables in FOP.
my xml-file looks like this:
<allgemein>
<verteiler>
<summary>
<name>User1</name>
<name>User2</name>
</summary>
<detail>
<name>User3</name>
<name>User4</name>
</detail>
</verteiler>
</allgemein>
and here's my xsl-file:
<xsl:for-each select="//verteiler/detail/name">
<xsl:variable name="anzahl"><xsl:number value="position()"
format="1"/></xsl:variable>
<fo:table-row line-height="1cm" border="solid 1px black">
<fo:table-cell>
<fo:block text-align="start" font-weight="bold">
<!-- <xsl:value-of select="$anzahl"/> with this i get number 1 and
2 in cell1-->
<!-- here i want to get User1 and User2 -->
<xsl:value-of select="//verteiler/summary/name[$anzahl]"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="start" font-weight="bold">
<xsl:value-of select="."/> <!-- here i get User3 and User4
-->
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
I want to get User1 and User2 in the first cell, User3 and User4 in the
second cell. It can also be that there are more users in <detail> than in
<summary>.
I always get User1 in cell1 row1 and 2 - never User2! In the second I see
User3 and User4. When I use instead "//verteiler/summary/name[2]" I get User2.
I don't understand why the value of the variable is not used here. I've seen
the use of variables in this way in many tutorials but for me it doesn't
work. I now it's an XSL problem, but maybe it is because of FOP.
Thanks for your help,
Markus
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
Re: use of variables in xsl:value-of
Posted by Oleg Tkachenko <ol...@multiconn.com>.
inchi2000@gmx.de wrote:
> I have problems with the use of variables in FOP.
Actually the problem has nothing to do with fop, instead it's fully xslt/xpath
stuff, you'd better ask in xsl-list.
> <xsl:variable name="anzahl"><xsl:number value="position()"
> format="1"/></xsl:variable>
Do you realize $anzahl this way is type of result tree fragment (rtf) and not
number?
> <fo:table-row line-height="1cm" border="solid 1px black">
> <fo:table-cell>
> <fo:block text-align="start" font-weight="bold">
> <!-- <xsl:value-of select="$anzahl"/> with this i get number 1 and
> 2 in cell1-->
> <!-- here i want to get User1 and User2 -->
> <xsl:value-of select="//verteiler/summary/name[$anzahl]"/>
As $anzahl is not number type, it evaluates to boolean type and as rtf is
never empty it's always true, so the line is equivalent to
<xsl:value-of select="//verteiler/summary/name"/>
which always outputs string value of the first name element in document order.
You can either change variable definition to
<xsl:variable name="anzahl" select="position()"/>
or explicitly compare position() and $anzahl:
<xsl:value-of select="//verteiler/summary/name[position() = $anzahl]"/>
--
Oleg Tkachenko
Multiconn International, Israel