XSLT-转换日期的条件格式不起作用

问题描述 投票:0回答:1

(使用XML 1.0)

我正在尝试有条件地格式化TradeDate的值:

                    <fo:table-cell padding="1mm" border-width="0.5mm" border-style="none">
                      <fo:block text-align="right" color="{$TradeDateAlert}">
                        <xsl:value-of select="TradeDate"/
                      </fo:block>
                    </fo:table-cell>

XML文件中的日期格式为:YYYY-MM-DD。

这是我创建的变量/函数:

                  <xsl:variable name="TradeDateAlert" select="10000 * substring(TradeDate, 1, 4) + 100 * substring(TradeDate, 6, 2) + substring(TradeDate, 9, 2)"/>
                  <xsl:choose>
                    <xsl:when test="$TradeDateAlert > 20200401">red</xsl:when>
                    <xsl:otherwise>green</xsl:otherwise>
                  </xsl:choose>

我可以看到使用[]正确地转换了日期>

 <xsl:value-of select="$TradeDateAlert"/>

编辑:添加XML代码段

<?xml version="1.0" ?>
<Deals xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <GroupedDeal TicketNumber="20">
    <Tickets>
      <TicketNumber>20</TicketNumber>
      <PartyA>Joe</PartyA>
      <PartyB>Bill</PartyB>
      <PrincipalAmount>100</PrincipalAmount>
      <TradeDate>2020-03-29</TradeDate>
    </Tickets>
  </GroupedDeal>
</Deals>

编辑#2:完整XSL:

<?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:output method="xml" indent="yes"/>

  <xsl:param name="username"></xsl:param>
  <xsl:param name="generatedOnDate"></xsl:param>

  <xsl:template match="/">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

      <fo:layout-master-set>
        <fo:simple-page-master master-name="table" page-height="11in" page-width="8.5in" margin-top=".5in"
                               margin-bottom=".5in" margin-left=".5in" margin-right=".5in">
          <fo:region-body margin-top="1in" margin-bottom="1in"/>
          <fo:region-before extent=".5in"/>
          <fo:region-after extent=".5in"/>
        </fo:simple-page-master>
      </fo:layout-master-set>

      <fo:page-sequence master-reference="table">

        <fo:static-content flow-name="xsl-region-before" text-align="center">
          <fo:block font-family="Times New Roman" font-size="11pt" font-weight="bold">
            Grouped Deals
          </fo:block>
          <fo:block font-family="Calibri" font-size="10pt" color="purple" text-align="left">
            Generated by 
          <xsl:value-of select="$username" /> on 
          <xsl:value-of select="$generatedOnDate" />
          </fo:block>
        </fo:static-content>

        <fo:static-content flow-name="xsl-region-after">
          <fo:block text-align="right" font-size="9pt">
            Page <fo:page-number/> <!-- of <fo:page-number-citation-last/> -->
          </fo:block>
        </fo:static-content>

        <fo:flow flow-name="xsl-region-body">

          <fo:table-caption>
            <fo:block>
              Any text, intermingled with:
              <fo:block>
                Any text, intermingled with:...
              </fo:block>
            </fo:block>
          </fo:table-caption>
          <fo:table table-layout="fixed" border-width="0.5mm" border-style="none"
                    font-size="10pt" font-style="Calibri" space-before="10pt">
            <fo:table-column column-width="1.5in"/>
            <fo:table-column column-width="1.5in"/>
            <fo:table-column column-width="1.5in"/>
            <fo:table-column column-width="1.5in"/>

            <fo:table-header text-align="center" background-color="silver">
              <fo:table-row>
                <fo:table-cell padding="1mm" border-width="0.5mm" border-style="none">
                  <fo:block font-weight="bold">Party A</fo:block>
                </fo:table-cell>
                <fo:table-cell padding="1mm" border-width="0.5mm" border-style="none">
                  <fo:block font-weight="bold">Party B</fo:block>
                </fo:table-cell>
                <fo:table-cell padding="1mm" border-width="0.5mm" border-style="none">
                  <fo:block font-weight="bold">Principal Amount</fo:block>
                </fo:table-cell>
                <fo:table-cell padding="1mm" border-width="0.5mm" border-style="none">
                  <fo:block font-weight="bold">Trade Date</fo:block>
                </fo:table-cell>
              </fo:table-row>
            </fo:table-header>

            <fo:table-body>

              <xsl:for-each select="Deals/GroupedDeal">


                <fo:table-row>
                  <fo:table-cell>
                    <fo:block>
                      <fo:leader />
                    </fo:block>
                  </fo:table-cell>
                </fo:table-row>

                <fo:table-row background-color="lightgreen" >
                  <fo:table-cell padding="1mm" border-width="0.5mm" border-style="none" >
                    <fo:block font-style="bold">
                      Ticket #:
                      <xsl:value-of select="@TicketNumber"/>
                    </fo:block>
                  </fo:table-cell>
                </fo:table-row>
                <xsl:for-each select="Tickets">

                  <xsl:variable name="bgclr">
                    <xsl:choose>
                      <xsl:when test="position() mod 2">#EDF2F8 </xsl:when>
                      <xsl:otherwise>#A7BFDE</xsl:otherwise>
                    </xsl:choose>
                  </xsl:variable>

                  <xsl:variable name="pamountColor">
                    <xsl:choose>
                      <xsl:when test = "PrincipalAmount > 100000">blue</xsl:when>
                      <xsl:otherwise>black</xsl:otherwise>
                    </xsl:choose>
                  </xsl:variable>

                  <xsl:variable name="partyBAlert">
                    <xsl:choose>
                      <xsl:when test = "PartyB = 'LAZARD-TK6258'">red</xsl:when>
                      <xsl:otherwise>black</xsl:otherwise>
                    </xsl:choose>
                  </xsl:variable>

                  <!--Trade Date format: 2020-03-29-->
                  <xsl:variable name="TradeDateAlert" select="10000 * substring(TradeDate, 1, 4) + 100 * substring(TradeDate, 6, 2) + substring(TradeDate, 9, 2)"/>
                  <xsl:choose>
                    <xsl:when test="$TradeDateAlert > 20200401">red</xsl:when>
                    <xsl:otherwise>green</xsl:otherwise>
                  </xsl:choose>

                  <fo:table-row background-color="{$bgclr}">

                    <fo:table-cell padding="1mm" border-width="0.5mm" border-style="none">
                      <fo:block>
                        <xsl:value-of select="PartyA"/>
                      </fo:block>
                    </fo:table-cell>
                    <fo:table-cell padding="1mm" border-width="0.5mm" border-style="none">
                      <fo:block color="{$partyBAlert}">
                        <xsl:value-of select="PartyB"/>
                      </fo:block>
                    </fo:table-cell>
                    <fo:table-cell padding="1mm" border-width="0.1mm" border-style="none" >
                      <fo:block text-align="right" color="{$pamountColor}">
                        <xsl:value-of select="format-number(PrincipalAmount, '$#,##0.00')"/>
                      </fo:block>
                    </fo:table-cell>

                    <fo:table-cell padding="1mm" border-width="0.5mm" border-style="none">
                      <fo:block text-align="right" color="{$TradeDateAlert}">
                        <xsl:value-of select="TradeDate"/>
                        <!--<xsl:value-of select="$TradeDateAlert"/>-->
                      </fo:block>
                    </fo:table-cell>

                  </fo:table-row>
                </xsl:for-each>
              </xsl:for-each>
            </fo:table-body>

          </fo:table>


        </fo:flow>

      </fo:page-sequence>

    </fo:root>
  </xsl:template>
</xsl:stylesheet>

我在做什么错?

谢谢,

(使用XML 1.0)我试图有条件地格式化TradeDate的值:<...>[

xslt xslt-1.0 xsl-fo
1个回答
0
投票

我想代替

© www.soinside.com 2019 - 2024. All rights reserved.