[英]XPATH/XSL : Unable to retrieve node elements using node-set
我正在尝试将两个表连接在一起并输出一个表。 表“常规显示”包含值“ BASICSA”,该值需要与表“所有费率”相匹配,表“所有费率”保存该值的数据。
下面是我的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]"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.