My problem has not been solved yet. The reason that I want use
xsl:variable is that I need to create a cross tab table. Without
infopath , I have a solution, there are two file, one is xml, one is
xsl to transform the xml into html. This xsl has been tested to able
to do the transformation.
xml is about a activitylist
<?xml version="1.0" encoding="utf-8" ?>
<ActivityList>
<Item>
<Day>1</Day>
<Type>Meal</Type>
<Name>Breakfast</Name>
<Note></Note>
</Item>
<Item>
<Day>1</Day>
<Type>Meal</Type>
<Name>Dinner</Name>
<Note>lots of stuff</Note>
</Item>
<Item>
<Day>1</Day>
<Type>Tour</Type>
<Name>Great wall</Name>
<Note></Note>
</Item>
<Item>
<Day>2</Day>
<Type>Meal</Type>
<Name>Breakfast</Name>
<Note></Note>
</Item>
<Item>
<Day>2</Day>
<Type>Airport</Type>
<Name>Transfer to hotel</Name>
<Note></Note>
</Item>
<Item>
<Day>3</Day>
<Type>Airport</Type>
<Name>Transfer to airport</Name>
<Note></Note>
</Item>
<Item>
<Day>3</Day>
<Type>Meeting</Type>
<Name>Face to face meeting</Name>
<Note></Note>
</Item>
</ActivityList>
the xsl is transform the day into column, type to row, and name to
data.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/
Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-
prefixes="msxsl"<xsl
utput method="html" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="distinctDayList" select="/ActivityList/
Item[not(Day=preceding-sibling::Item/Day)]/Day"></xsl:variable>
<xsl:variable name ="distinctTypeList" select="/ActivityList/
Item[not(Type=preceding-sibling::Item/Type)]/Type"></xsl:variable>
<html>
<header>
<style type="text/css">
table, td, th
{
border:solid 1px black
}
table
{
border-collapse:collapse;
}
</style>
</header>
<body>
<h1>Cross tab demo</h1>
<table>
<tr>
<!--build day row-->
<th>Type</th>
<xsl:for-each select="$distinctDayList">
<xsl:sort select="Day"/>
<th>
<xsl:value-of select="."/>
</th>
</xsl:for-each>
</tr>
<xsl:for-each select="$distinctTypeList">
<xsl:sort select="Type" data-type="text"/>
<tr>
<td>
<xsl:value-of select="."/>
</td>
<xsl:variable name="currentType" select="."></xsl:variable>
<xsl:for-each select="$distinctDayList" >
<td>
<xsl:for-each select="/ActivityList/Item[Day=current() and
Type=$currentType]">
<xsl:value-of select="Name"/>
<xsl:if test="position()!=last()">
,
</xsl:if>
</xsl:for-each>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Infopath designer can not achieve that , so I need to open the
view1.xsl in text editor. and make the following change
<!-- leave out lots infopath tag above -->
<xsl:template match="/">
<xsl:variable name="distinctDayList" select="/ActivityList/
Item[not(Day=preceding-sibling::Item/Day)]/Day"></xsl:variable>
<xsl:variable name ="distinctTypeList" select="/ActivityList/
Item[not(Type=preceding-sibling::Item/Type)]/Type"></xsl:variable>
<html>
<head>
<!-- leave out lots infopath tag here -->
</head>
<body style="COLOR: #000000; BACKGROUND-COLOR: #ffffff">
<h1>Cross tab demo</h1>
<table>
<tr>
<!--build day row-->
<th>Type</th>
<xsl:for-each select="$distinctDayList">
<xsl:sort select="Day"/>
<th>
<xsl:value-of select="."/>
</th>
</xsl:for-each>
</tr>
<xsl:for-each select="$distinctTypeList">
<xsl:sort select="Type" data-type="text"/>
<tr>
<td>
<xsl:value-of select="."/>
</td>
<xsl:variable name="currentType" select="."></xsl:variable>
<xsl:for-each select="$distinctDayList" >
<td>
<xsl:for-each select="/ActivityList/Item[Day=current() and
Type=$currentType]">
<xsl:value-of select="Name"/>
<xsl:if test="position()!=last()">
,
</xsl:if>
</xsl:for-each>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
When I design xsf , I got this message,
A view in the form template contains a structure that InfoPath does
not support.
Structure details:
<xsl:variable xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
name="distinctTypeList" select="/ActivityList/Item[not(Type=preceding-
sibling::Item/Type)]/Type"></xsl:variable>
The variable is at the top template, so scope should be accessible in
inner level. First I think is the xpath expression seems to be not
friendly to infopath. So I change it to a very simple expression, but
it still complained the same thing, so I think variable is the
problem. Inofpath is xsl based solution, why it does not support this
valid xsl? Does infopath team or somebody has an answer to this?
Thanks
Fred