我需要一些关于XSLT的帮助。计算XSLT1.0中的行数
我得到一个XML文件,我需要在文件中报告一些数据两次,soem数据需要过滤掉。
并在页脚上我需要准确报告文件中有多少行。
是否有人可以帮助我在这里感谢
这里是我的XML:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<ns0:File xmlns:ns0="file">
<ns0:Records>
<ns0:Main>
<ns0:Info>
<ns0:InternalCode>1</ns0:InternalCode>
<ns0:Name>test1</ns0:Name>
<ns0:Factor>2.000000000000</ns0:Factor>
<ns0:Type>a</ns0:Type>
</ns0:Info>
</ns0:Main>
<ns0:Main>
<ns0:Info>
<ns0:InternalCode>2</ns0:InternalCode>
<ns0:Name>test2</ns0:Name>
<ns0:Factor>10.000000000000</ns0:Factor>
<ns0:Type>c</ns0:Type>
</ns0:Info>
</ns0:Main>
<ns0:Main>
<ns0:Info>
<ns0:InternalCode>3</ns0:InternalCode>
<ns0:Name>test3</ns0:Name>
<ns0:Factor>13.000000000000</ns0:Factor>
<ns0:Type>b</ns0:Type>
</ns0:Info>
</ns0:Main>
<ns0:Main>
<ns0:Info>
<ns0:InternalCode>4</ns0:InternalCode>
<ns0:Name>test4</ns0:Name>
<ns0:Factor>1.000000000000</ns0:Factor>
<ns0:Type>a</ns0:Type>
</ns0:Info>
</ns0:Main>
<ns0:Main>
<ns0:Info>
<ns0:InternalCode>5</ns0:InternalCode>
<ns0:Name>test5</ns0:Name>
<ns0:Factor>1.000000000000</ns0:Factor>
<ns0:Type>f</ns0:Type>
</ns0:Info>
</ns0:Main>
</ns0:Records>
<ns0:Footer>
<ns0:Time>10:54:40</ns0:Time>
<ns0:NumberOfRecords>5</ns0:NumberOfRecords>
</ns0:Footer>
</ns0:File>
这里是我的XSLT:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="file">
<xsl:output method="text"
encoding="ASCII"/>
<xsl:template match="ns0:Main">
<xsl:variable name="substractone">
<xsl:value-of select="ns0:Info/ns0:Factor-1"/>
</xsl:variable>
<xsl:if test=" ns0:Factor !=0 and ns0:Type !='c' and $substractone !=0 ">
<xsl:choose>
<xsl:when test="ns0:Type = 'a'">
<xsl:value-of select="ns0:InternalCode"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="ns0:Name"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="ns0:Factor"/>
<xsl:text>
</xsl:text>
<!-- repeat in a new line -->
<xsl:value-of select="ns0:InternalCode"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="ns0:Name"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="ns0:Factor"/>
<xsl:text>
</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ns0:InternalCode"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="ns0:Name"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="ns0:Factor"/>
<xsl:text>
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template match="ns0:Footer">
<!--Footer row-->
<xsl:text>
</xsl:text>
<xsl:text>*</xsl:text>
<xsl:value-of select="ns0:NumberOfRecords"/>
<!--record total-->
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
正如你可以看到NS0:NumberOfRecords会在这里返回5,但实际上这个文件有4行(过滤出type = c,每行为= 2行)
有人可以告诉我如何才能正确地获取文件中的行数?
你明明看着我的答案(因为你在你的代码,我指出纠正错误)。你介意告诉我它是否解决了你的问题?顺便说一下,请接受这里的答案之一:http://stackoverflow.com/questions/12743828/how-to-do-square-root-in-xslt-1-0 –