这是我的XML格式
<Formsxml CM="7" CW="3">
<Forms GroupName="Kingfisher" PRONME="Kingfisher" TBONUSP="6000" NACRES="45" TP="133.333333">
<Form M="1" GroupName="Kingfisher January" PRONME="Kingfisher" TBONUSP="1000" NACRES="7.50" TP="133.333333" />
<Form M="2" GroupName="Kingfisher Feb" PRONME="Kingfisher" TBONUSP="1000" NACRES="7.50" TP="133.333333" />
<Form M="5" GroupName="Kingfisher May" PRONME="Kingfisher" TBONUSP="1000" NACRES="7.50" TP="133.333333" />
<Form M="6" GroupName="Kingfisher July" TBONUSP="1000" NACRES="7.50" TP="133.333333" />
<Form W="3" GroupName="Kingfisher Week 3 Total" TBONUSP="2000" NACRES="7.50" TP="133.333333" />
</Forms>
<Forms GroupName="Pigeon" PRONME="Pigeon" TBONUSP="5000" NACRES="55555.00" TP="0.018000">
<Form M="5" GroupName="Pigeon May" PRONME="Pigeon" TBONUSP="1000" NACRES="7.50" TP="133.333333" />
<Form M="6" GroupName="Pigeon July" TBONUSP="1000" NACRES="7.50" TP="133.333333" />
<Form W="1" GroupName="Pigeon Week 1 Total" TBONUSP="2000" NACRES="7.50" TP="133.333333" />
</Forms>
<Forms GroupName="Sparrow" PRONME="Sparrow" TBONUSP="1000" NACRES="0.90" TP="1111.111111">
<Form M="6" GroupName="Sparrow July" TBONUSP="1000" NACRES="7.50" TP="133.333333" />
<Form W="4" GroupName="Sparrow July" TBONUSP="1000" NACRES="7.50" TP="133.333333" />
</Forms>
</Formsxml>这是我的XSLT1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<table cellspacing="0" cellpadding="0" width="100%" border="1" borderColorDark="#ffffff" borderColorLight="#000000" class="smlFonts">
<tr height="20" align="center">
<td rowspan="1" width="10%"><b>Name</b></td>
<td rowspan="1" width="7%"><b>Net</b></td>
<td rowspan="1" width="7%"><b>Total</b></td>
<td rowspan="1" width="8%"><b>Average</b></td>
<xsl:apply-templates select="*/Forms"/>
</tr>
</table>
</xsl:template>
<xsl:template match="Forms">
<xsl:apply-templates select="Form"/>
<tr style="color:red">
<td>
<xsl:value-of select="@NAME"/> Total
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:template>
<xsl:template match="Form">
<xsl:choose>
<xsl:when test="@M ='1'">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise><tr>
<td>
January
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@M ='2'">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise><tr>
<td>
Febuary
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@M ='3'">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise><tr>
<td>
March
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@M ='4'">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise><tr>
<td>
April
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@M ='5'">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise><tr>
<td>
May
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@M ='6'">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise><tr>
<td>
June
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@M ='7'">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise><tr>
<td>
July
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@M ='8'">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise><tr>
<td>
August
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@M ='9'">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise><tr>
<td>
September
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@M ='10'">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise><tr>
<td>
October
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@M ='11'">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise><tr>
<td>
November
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr></xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@M ='12'">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise><tr>
<td>
December
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>,但我想输出像This...Based一样的条件,CM意味着如果它的7只到6月份,然后根据周CW,如果它的第3周,第3周,我想打印任何帮助将是Appreciated........See图像的更多细节。
输出我期望..。

发布于 2011-07-29 21:23:38
恐怕你对十二条xsl:choose指令的努力是完全徒劳的,逻辑上也是错误的。
您可以用较少的精力获得想要的结果,但您需要一个查找表的几个月。下面的转换只是一个“开始”。运行一下,您就会注意到:
对于每个窗体组,只有所需的行将被打印(所有月份)
您可能还需要完成当前填充到7月的查找表。
XSLT1.0
<xsl:stylesheet version="1.0"
xmlns:empo="http://stackoverflow.com/users/253811/empo"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<empo:months>
<empo:M id="1">Jan</empo:M>
<empo:M id="2">Feb</empo:M>
<empo:M id="3">Mar</empo:M>
<empo:M id="4">Apr</empo:M>
<empo:M id="5">May</empo:M>
<empo:M id="6">Jun</empo:M>
<empo:M id="7">Jul</empo:M>
</empo:months>
<xsl:template match="/">
<table cellspacing="0" cellpadding="0" width="100%" border="1" borderColorDark="#ffffff" borderColorLight="#000000" class="smlFonts">
<tr height="20" align="center">
<td rowspan="1" width="10%"><b>Name</b></td>
<td rowspan="1" width="7%"><b>Net</b></td>
<td rowspan="1" width="7%"><b>Total</b></td>
<td rowspan="1" width="8%"><b>Average</b></td>
<xsl:apply-templates select="*/Forms"/>
</tr>
</table>
</xsl:template>
<xsl:template match="Forms">
<xsl:variable name="Forms" select="."/>
<xsl:for-each select="document('')/*/
empo:months/empo:M[@id <= $Forms/../@CM]">
<xsl:choose>
<xsl:when test="$Forms/Form[@M=current()/@id]">
<xsl:apply-templates
select="$Forms/Form[@M=current()/@id]"/>
</xsl:when>
<xsl:otherwise>
<tr>
<td>
<xsl:value-of select="."/>
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<tr style="color:red">
<td>
<xsl:value-of select="@NAME"/>
<xsl:text> Total</xsl:text>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:template>
<xsl:template match="Form">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>发布于 2011-08-01 06:25:31
<xsl:stylesheet version="1.0"
xmlns:empo="http://www.w3.org/1999/XSL/Transform/empo"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<empo:months>
<empo:M id="1">Jan</empo:M>
<empo:M id="2">Feb</empo:M>
<empo:M id="3">Mar</empo:M>
<empo:M id="4">Apr</empo:M>
<empo:M id="5">May</empo:M>
<empo:M id="6">Jun</empo:M>
<empo:M id="7">Jul</empo:M>
<empo:M id="8">August</empo:M>
<empo:M id="9">September</empo:M>
<empo:M id="10">October</empo:M>
<empo:M id="11">November</empo:M>
<empo:M id="12">December</empo:M>
</empo:months>
<empo:Weeks>
<empo:M id="1">Week 1</empo:M>
<empo:M id="2">Week 2</empo:M>
<empo:M id="3">Week 3</empo:M>
<empo:M id="4">Week 4</empo:M>
<empo:M id="5">Week 5</empo:M>
</empo:Weeks>
<xsl:template match="/">
<table cellspacing="0" cellpadding="0" width="100%" border="1" borderColorDark="#ffffff" borderColorLight="#000000" class="smlFonts">
<tr height="20" align="center">
<td rowspan="1" width="10%"><b>Name</b></td>
<td rowspan="1" width="7%"><b>Net</b></td>
<td rowspan="1" width="7%"><b>Total</b></td>
<td rowspan="1" width="8%"><b>Average</b></td>
<xsl:apply-templates select="*/Forms"/>
</tr>
</table>
</xsl:template>
<xsl:template match="Forms">
<xsl:variable name="Forms" select="."/>
<xsl:for-each select="document('')/*/
empo:months/empo:M[@id < $Forms/../@CM]">
<xsl:choose>
<xsl:when test="$Forms/Form[@M=current()/@id]">
<xsl:apply-templates select="$Forms/Form[@M=current()/@id]"/>
</xsl:when>
<xsl:otherwise>
<tr>
<td>
<xsl:value-of select="."/>
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="document('')/*/
empo:Weeks/empo:M[@id <= $Forms/../@CW]">
<xsl:choose>
<xsl:when test="$Forms/Form[@W=current()/@id]">
<xsl:apply-templates select="$Forms/Form[@W=current()/@id]"/>
</xsl:when>
<xsl:otherwise>
<tr>
<td>
<xsl:value-of select="."/>
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<tr style="color:red">
<td>
<xsl:value-of select="@NAME"/>
<xsl:text> Total</xsl:text>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:template>
<xsl:template match="Form">
<tr>
<td>
<xsl:value-of select="@GroupName"/>
</td>
<td>
<xsl:value-of select="@NACRES"/>
</td>
<td>
<xsl:value-of select="@TBONUSP"/>
</td>
<td>
<xsl:value-of select="@TP"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>发布于 2011-08-03 11:58:34
<xsl:for-each select="document('')/*/
empo:Weeks/empo:M[@id <= $Forms/../@CW]">
<xsl:choose>
<xsl:when test="$Forms/Form[@W=current()/@id]">
<xsl:apply-templates select="$Forms/Form[@W=current()/@id]"/>
</xsl:when>
<xsl:otherwise>
<tr>
<td>
<xsl:value-of select="concat($Forms/@PRONME,' ',., ' ','Total')"/>
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
<td>
0.0000
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>https://stackoverflow.com/questions/6875445
复制相似问题