我正在尝试将两个表连接在一起并输出一个表。表"常规显示"保留值"基础",该值需要匹配表"所有速率",该表"所有速率"保存该值的数据。
下面是我的XML
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="ConvDispData.xsl"?>
<Rates xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<TableList>
<Table name="Conventional Display">
<Tbody>
<Tr>
<Td>BASICSA </Td>
</Tr>
</Tbody>
</Table>
<Table name="All Rates">
<Tbody>
<Tr>
<Td>BASICSA </Td>
<Td>balanceLimit001 </Td>
<Td>rateamou1 </Td>
</Tr>
</Tbody>
</Table>
</TableList>
</Rates>
及以下是我的XSL
<?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" xmlns:ext="http://exslt.org/common"
exclude-result-prefixes="ext msxsl"
>
<xsl:output method="xml" />
<xsl:variable name="TABLE_NAME">All Rates</xsl:variable>
<xsl:variable name="ALL_RATES_TR" select="//Table[@name=$TABLE_NAME]/Tbody/Tr" />
<xsl:variable name="CONV_TABLE_NAME">Conventional Display</xsl:variable>
<xsl:variable name="TITLE1">Conventional Display</xsl:variable>
<xsl:variable name="COLUMN1">WT-RATE-NUMBER</xsl:variable>
<xsl:variable name="COLUMN2">WT-AMOUNT-TO-CHECK(1)</xsl:variable>
<xsl:variable name="COLUMN3">WT-SPLIT-TIER-RATE(1)</xsl:variable>
<xsl:variable name="REC_PER_PAGE">10</xsl:variable>
<xsl:template match="/">
<Rates>
<TableList>
<Table name="{$CONV_TABLE_NAME}" cellspacing="0" cellpadding="0" class="tblDeposit">
<RecordPerPage>
<xsl:value-of select="$REC_PER_PAGE"/>
</RecordPerPage>
<xsl:call-template name="BuildHeader"/>
<Tbody>
<xsl:apply-templates select="//Table[@name=$CONV_TABLE_NAME]/Tbody/Tr">
</xsl:apply-templates>
</Tbody>
</Table>
</TableList>
</Rates>
</xsl:template>
<xsl:template name="BuildHeader">
<Thead>
<Tr>
<Td class="tdDepositHeaderType">
<xsl:value-of select="$COLUMN1"/>
</Td>
<Td class="tdDepositHeaderRates">
<xsl:value-of select="$COLUMN2"/>
</Td>
<Td class="tdDepositHeaderRates">
<xsl:value-of select="$COLUMN3"/>
</Td>
</Tr>
</Thead>
</xsl:template>
<xsl:template match="Tr">
<xsl:param name="PreClass"/>
<xsl:variable name="Position">
<xsl:value-of select="position()"/>
</xsl:variable>
<xsl:variable name="Class">
<xsl:choose>
<xsl:when test="$PreClass=''">
<xsl:call-template name="SectionClass">
<xsl:with-param name="Pos">
<xsl:value-of select="$Position"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$PreClass"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="RATEID" select="Td[1]"/>
<xsl:variable name="MATCHEDTD" select="ext:node-set($ALL_RATES_TR)/Tbody" />
<Tr>
<xsl:attribute name="Class">
<xsl:value-of select="$Class"/>
</xsl:attribute>
<Td class="tdDepositType">
<xsl:value-of select="$RATEID"/>
</Td>
<Td class="tdDepositType">
<xsl:value-of select="MATCHEDTD[2]"/>
</Td>
<Td class="tdDepositType">
<xsl:value-of select="MATCHEDTD[3]"/>
</Td>
</Tr>
</xsl:template>
<xsl:template name="SectionClass">
<xsl:param name="Pos"/>
<xsl:choose>
<xsl:when test="$Pos mod 2 != 0">TOdd</xsl:when>
<xsl:otherwise>TEven</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
我对此代码的问题在这里:
使用LiquidStudio,我可以看到,如果我执行ext:node-set($ all_rates_tr(,我会得到一系列值,即tbody。但是,每当我尝试使用任何XPATH检索tbody的较好值时,选择都会返回空。
我不明白为什么它可以空返回,即使路径应该正确。
非常感谢。
您实际上不需要在此处使用node-set
。您的$ALL_RATES_TR
在输入文档中引用节点,因此已经设置了节点。
另外,$ALL_RATES_TR
选择了表的Tr
元素,因此尝试在其下选择TBody
是没有意义的。您可能是要选择Td
这样的...
<xsl:variable name="MATCHEDTD" select="$ALL_RATES_TR/Td" />
这样做之后,另一个问题是您在尝试访问MATCHEDTD
时忘记了添加$
前缀。当您应该这样做时,您正在做<xsl:value-of select="MATCHEDTD[2]"/>
...
<xsl:value-of select="$MATCHEDTD[2]"/>