Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 复制模板时如何重新计算位置_Xslt - Fatal编程技术网

Xslt 复制模板时如何重新计算位置

Xslt 复制模板时如何重新计算位置,xslt,Xslt,我想问一下,当我从另一个xml文件复制模板时,如果满足代码应该与lookup.xml中的代码相同的条件,如何重新计算行号位置和其他数据 我的程序是这样的: <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 omit-xml-declaration="

我想问一下,当我从另一个xml文件复制模板时,如果满足代码应该与lookup.xml中的代码相同的条件,如何重新计算行号位置和其他数据

我的程序是这样的:

<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 omit-xml-declaration="yes" indent="yes"/>   
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template> 
    <xsl:template match="Line-Item[code = document('lookup.xml')/*/*/code]" />
    <xsl:template match="Line[not(Line-Item/code[not(. = document('lookup.xml')/*/*/code ) ] )]"/>  
</xsl:stylesheet>
Lookup.xml文件:

<lookup>
    <Codes>
        <code>123</code>
    </Codes>
</lookup>
我需要重新计算行项目中的LineNum,汇总有总行和总金额

正确结果:

<document>
    <header>
        <remarks>test</remarks>
    </header>
    <Line>
        <Line-Item>
            <lineNumb>1</lineNumb>
            <code>444</code>
            <amount>2</amount>
        </Line-Item>
        <Line-Item>
            <lineNumb>2</lineNumb>
            <code>321</code>
            <amount>1</amount>
        </Line-Item>
    </Line>
    <summary>
        <total-line>2</total-line>
        <total-amount>3</total-amount>
    </summary>
</document>

你的工作差不多完成了。您只需要XPath
count()
sum()
。为了重新计算
lineNumb
,我计算了所有以前的同级元素,但与查找代码匹配的元素除外

根据你的假设,我认为这应该很好


XSLT 1.0在Saxon-b9.0.0.4J上测试

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>   

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Line">

        <xsl:copy>
            <xsl:apply-templates select="Line-Item"/>
        </xsl:copy>

        <xsl:variable name="lines" select="count(Line-Item[not(code = document('lookup.xml')/*/*/code)])"/>
        <xsl:variable name="amount" select="sum(Line-Item[not(code = document('lookup.xml')/*/*/code)]/amount)"/>

        <summary>
            <total-line><xsl:value-of select="$lines"/></total-line>
            <total-amount><xsl:value-of select="$amount"/></total-amount>
        </summary>
    </xsl:template>

    <xsl:template match="Line-Item">
        <xsl:copy>
            <lineNumb>
                <xsl:value-of select="count(preceding-sibling::*[not(code = document('lookup.xml')/*/*/code)])+1"/>
            </lineNumb>
            <xsl:copy-of select="code"/>
            <xsl:copy-of select="amount"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Line-Item[code = document('lookup.xml')/*/*/code]|summary" />

</xsl:stylesheet>

你的工作差不多完成了。您只需要XPath
count()
sum()
。为了重新计算
lineNumb
,我计算了所有以前的同级元素,但与查找代码匹配的元素除外

根据你的假设,我认为这应该很好


XSLT 1.0在Saxon-b9.0.0.4J上测试

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>   

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Line">

        <xsl:copy>
            <xsl:apply-templates select="Line-Item"/>
        </xsl:copy>

        <xsl:variable name="lines" select="count(Line-Item[not(code = document('lookup.xml')/*/*/code)])"/>
        <xsl:variable name="amount" select="sum(Line-Item[not(code = document('lookup.xml')/*/*/code)]/amount)"/>

        <summary>
            <total-line><xsl:value-of select="$lines"/></total-line>
            <total-amount><xsl:value-of select="$amount"/></total-amount>
        </summary>
    </xsl:template>

    <xsl:template match="Line-Item">
        <xsl:copy>
            <lineNumb>
                <xsl:value-of select="count(preceding-sibling::*[not(code = document('lookup.xml')/*/*/code)])+1"/>
            </lineNumb>
            <xsl:copy-of select="code"/>
            <xsl:copy-of select="amount"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Line-Item[code = document('lookup.xml')/*/*/code]|summary" />

</xsl:stylesheet>


Hi,但lineNumb不会重新计算。我的意思是lineNumb position=2和3,然后应该是1和2,因为首先我们删除了。很抱歉,我没有看到具体的:)。我会尽快尝试。答案现在包括
lineNumb
重新计算。希望这是你需要的。嗨,但是lineNumb不会重新计算。我的意思是lineNumb position=2和3,然后应该是1和2,因为首先我们删除了。很抱歉,我没有看到具体的:)。我会尽快尝试。答案现在包括
lineNumb
重新计算。希望这是你需要的。