您好,我是XSLT新手,目前我尝试捕获两个变量,一个来自数据库,另一个是我自己的头部控制循环进程的NULL变量。我在这里没有找到任何帮助我解决这个问题的东西,所以这是我的代码:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output media-type="text/xml" method="xml"></xsl:output>
<xsl:template match="/">
<root>
<xsl:variable name="Counter" select="document('context:Counter')"></xsl:variable>
<xsl:variable name="Counted">
<xsl:value-of>0</xsl:value-of>
</xsl:variable>
<Counter>
<xsl:value-of select="$Counter"></xsl:value-of>
</Counter>
<Counted>
<xsl:value-of select="$Counted"></xsl:value-of>
</Counted>
<xsl:if test="not($Counted = $Counter)">
<xsl:processing-instruction name="ConditionState">
2000
</xsl:processing-instruction>
</xsl:if>
<xsl:if test="$Counted = $Counter">
<xsl:processing-instruction name="ConditionState">
2001
</xsl:processing-instruction>
</xsl:if>
</root>
</xsl:template>
</xsl:stylesheet>对于我的情况,我希望ConditionState在not equals上是2000,在equals上是2001。问题是他跳出了代码而我不知道为什么或者在哪里..。下面是我的错误:
net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException; Premature end of file.我希望这里有人能帮我这个忙。
发布于 2019-07-17 18:39:16
要结束这篇文章,这里是我的解决方案:
我的代码:
<?xml version="1.0" encoding="UTF-8"?><?xe.source ../Data/DBO_Output.xml#root?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output media-type="text/xml" method="xml"></xsl:output>
<xsl:template match="/">
<root>
<xsl:variable name="Counter">
<xsl:value-of select="./root"></xsl:value-of>
</xsl:variable>
<xsl:variable name="Counted" select="0">
</xsl:variable>
<Counter>
<xsl:value-of select="$Counter"></xsl:value-of>
</Counter>
<Counted>
<xsl:value-of select="$Counted"></xsl:value-of>
</Counted>
<xsl:if test="$Counter >= $Counted">
<xsl:processing-instruction name="ConditionState">
2000
</xsl:processing-instruction>
</xsl:if>
<xsl:if test="not($Counter >= $Counted) or $Counter = $Counted">
<xsl:processing-instruction name="ConditionState">
2001
</xsl:processing-instruction>
</xsl:if>
</root>
</xsl:template>
</xsl:stylesheet>我将数据库数据写入外部xml文件,然后读取该文件以获取转换所需的数据。
https://stackoverflow.com/questions/57036863
复制相似问题