Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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

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
Xml XSLT 2 |对于每个备选方案|在使用doc()时_Xml_Xslt_Foreach_Xslt 2.0_Lookup - Fatal编程技术网

Xml XSLT 2 |对于每个备选方案|在使用doc()时

Xml XSLT 2 |对于每个备选方案|在使用doc()时,xml,xslt,foreach,xslt-2.0,lookup,Xml,Xslt,Foreach,Xslt 2.0,Lookup,我一直在努力改变: …以下内容:[CSKS文件] <ZRFC_READ_TABLE.Response> <DATA> <item> <WA>20200306~99999999~123456~EUR ~6000~1234~HELO ~ ~</WA> </item> <item> <WA>2

我一直在努力改变:

…以下内容:[CSKS文件]

<ZRFC_READ_TABLE.Response>
    <DATA>
        <item>
            <WA>20200306~99999999~123456~EUR  ~6000~1234~HELO      ~ ~</WA>
        </item>
        <item>
            <WA>20200306~99999999~789012~EUR  ~6000~1234~HEYL      ~ ~</WA>
        </item>
        <item>
            <WA>20200306~99999999~345678~EUR  ~6000~1234~HIYA      ~ ~</WA>
        </item>
    </DATA>
</ZRFC_READ_TABLE.Response>

20200306~9999999~123456~6000~1234欧元~HELO~~
20200306~9999999~789012~6000~1234欧元~HEYL~~
20200306~9999999~345678~6000~1234欧元~HIYA~~
以下内容作为查找源:[CSKT doc]

<ZRFC_READ_TABLE.Response>
    <DATA>
        <item>
            <WA>123456~This is a test message 1~</WA>
        </item>
        <item>
            <WA>789012~This is a test message 2~</WA>
        </item>
        <item>
            <WA>345678~This is a test message 3~</WA>
        </item>
    </DATA>
</ZRFC_READ_TABLE.Response>

123456~这是一条测试消息1~
789012~这是一条测试消息2~
345678~这是一条测试消息3~
使用以下XSLT:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:param name="CSKT_FilePath"/>
    <xsl:param name="CSKS_FilePath"/>
    <xsl:template match="/">
        <xsl:element name="masterData">
            <xsl:choose>
                <xsl:when test="(not($CSKT_FilePath) and not(string($CSKT_FilePath))) and (not($CSKS_FilePath) and not(string($CSKS_FilePath)))">
                    <xsl:message terminate="yes">One or more Input Parameter(s) not supplied!</xsl:message>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:variable name="CSKTData" select="doc($CSKT_FilePath)"/>
                    <xsl:variable name="CSKSData" select="doc($CSKS_FilePath)"/>
                    <xsl:variable name="ReplaceFunction">
                        <ReplaceFunction name="LTEXT BY KOSTL">
                            <xsl:for-each select="$CSKTData/ZRFC_READ_TABLE.Response/DATA/item/WA">
                                <xsl:element name="item">
                                    <xsl:attribute name="key" select="replace(normalize-space(tokenize(., '~')[1]), '[^0-9a-zA-Z]+', '')"/>
                                    <!--<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>-->
                                    <xsl:value-of select="normalize-space(tokenize(., '~')[2])"/>
                                    <!--<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>-->
                                </xsl:element>
                            </xsl:for-each>
                        </ReplaceFunction>
                    </xsl:variable>             
                    <xsl:for-each select="$CSKSData/ZRFC_READ_TABLE.Response/DATA/item/WA">
                        <xsl:variable name="_ccDesc_In" select="replace(normalize-space(tokenize(., '~')[3]), '[^0-9a-zA-Z]+', '')"/>
                        <mdRec>
                            <dateFrom>
                                <xsl:value-of select="normalize-space(tokenize(., '~')[1])"/>
                            </dateFrom>
                            <dateTo>
                                <xsl:value-of select="normalize-space(tokenize(., '~')[2])"/>
                            </dateTo>
                            <costCenter>
                                <xsl:value-of select="normalize-space(tokenize(., '~')[3])"/>
                            </costCenter>
                            <cur>
                                <xsl:value-of select="normalize-space(tokenize(., '~')[4])"/>
                            </cur>
                            <contArea>
                                <xsl:value-of select="normalize-space(tokenize(., '~')[5])"/>
                            </contArea>
                            <compCode>
                                <xsl:value-of select="normalize-space(tokenize(., '~')[6])"/>
                            </compCode>
                            <profitCenter>
                                <xsl:value-of select="normalize-space(tokenize(., '~')[7])"/>
                            </profitCenter>
                            <lockInd>
                                <xsl:value-of select="normalize-space(tokenize(., '~')[8])"/>
                            </lockInd>
                            <ccDesc>
                                <xsl:value-of select="$ReplaceFunction//item[@key=$_ccDesc_In]/text()"/>
                            </ccDesc>
                        </mdRec>
                    </xsl:for-each>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

未提供一个或多个输入参数!
产生如下所示的所需输出:

<masterData>
    <mdRec>
        <dateFrom>20200306</dateFrom>
        <dateTo>99999999</dateTo>
        <costCenter>123456</costCenter>
        <cur>EUR</cur>
        <contArea>6000</contArea>
        <compCode>1234</compCode>
        <profitCenter>HELO</profitCenter>
        <lockInd/>
        <ccDesc>This is a test message 1</ccDesc>
    </mdRec>
    <mdRec>
        <dateFrom>20200306</dateFrom>
        <dateTo>99999999</dateTo>
        <costCenter>789012</costCenter>
        <cur>EUR</cur>
        <contArea>6000</contArea>
        <compCode>1234</compCode>
        <profitCenter>HEYL</profitCenter>
        <lockInd/>
        <ccDesc>This is a test message 2</ccDesc>
    </mdRec>
    <mdRec>
        <dateFrom>20200306</dateFrom>
        <dateTo>99999999</dateTo>
        <costCenter>345678</costCenter>
        <cur>EUR</cur>
        <contArea>6000</contArea>
        <compCode>1234</compCode>
        <profitCenter>HIYA</profitCenter>
        <lockInd/>
        <ccDesc>This is a test message 3</ccDesc>
    </mdRec>
</masterData>

20200306
99999999
123456
欧元
6000
1234
希洛
这是一条测试消息1
20200306
99999999
789012
欧元
6000
1234
海勒
这是一条测试消息2
20200306
99999999
345678
欧元
6000
1234
你好
这是一条测试消息3
在处理CSKS文档中WA子段的1000s[50000,准确地说]时,转换大约需要5-6分钟。这可能是由于单独使用for-each或构建不良的XSLT造成的。就性能而言,有更好的替代方案吗

在XSLT中声明一个键
作为顶级元素(即
xsl:stylesheet
xsl:transform
),然后使用
key($ReplaceFunction//item[@key=$\u ccDesc in]/text()
键('ltext-by-kostl',$\u ccDesc in,$ReplaceFunction))


如果不使所有这些
标记化
调用,而是在可能的情况下,只使用一次函数,并将其结果存储在变量中,例如
,然后在需要时访问
$tokens[1]
$tokens[2]

使用键或使用XSLT/XPath 3映射。@MartinHonnen,Thx,我确实看到了一些其他的SO讨论,其中提出了XSLT 3映射,但我希望在XSLT 2中实现所需的功能……这大大提高了性能。谢谢你,@MartinHonnen。这次行动耗时不到30秒。答案被接受。