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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/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转换通过循环将一种XML格式转换为另一种XML格式_Xml_Xslt - Fatal编程技术网

XSLT转换通过循环将一种XML格式转换为另一种XML格式

XSLT转换通过循环将一种XML格式转换为另一种XML格式,xml,xslt,Xml,Xslt,我的XSLT转换面临一个问题。我想将xml从一种形式转换为另一种形式。我的输入XML根标记是 输入XML: <ICWRRsp> <IcwrId>379505</IcwrId> <IcwrId>379506</IcwrId> <IcwrId>379507</IcwrId> <IcwrId>379508</IcwrId> <IcwrId>379509</IcwrId>

我的XSLT转换面临一个问题。我想将xml从一种形式转换为另一种形式。我的输入XML根标记是

输入XML:

<ICWRRsp>
<IcwrId>379505</IcwrId>
<IcwrId>379506</IcwrId>
<IcwrId>379507</IcwrId>
<IcwrId>379508</IcwrId>
<IcwrId>379509</IcwrId>
<IcwrId>379510</IcwrId>
<WorkId>1920305</WorkId>
<WorkId>1920475</WorkId>
<WorkId>1920673</WorkId>
<WorkId>1920676</WorkId>
<WorkId>1920717</WorkId>
<WorkId>1920729</WorkId>
<Jurisdiction>V1</Jurisdiction>
<Jurisdiction>V1</Jurisdiction>
<Jurisdiction>V1</Jurisdiction>
<Jurisdiction>V1</Jurisdiction>
<Jurisdiction>MD</Jurisdiction>
<Jurisdiction>MD</Jurisdiction>
<IcgsWc>0FCC</IcgsWc>
<IcgsWc>0FCC</IcgsWc>
<IcgsWc>0FCC</IcgsWc>
<IcgsWc>0FCC</IcgsWc>
<IcgsWc>0FEN</IcgsWc>
<IcgsWc>0FEN</IcgsWc>
<WcId>0</WcId>
<WcId>0</WcId>
<WcId>0</WcId>
<WcId>0</WcId>
<WcId>0</WcId>
<WcId>0</WcId>
<StatusCode>0</StatusCode>
<StatusDesc>SUCESS</StatusDesc>
</ICWRRsp>

379505
379506
379507
379508
379509
379510
1920305
1920475
1920673
1920676
1920717
1920729
V1
V1
V1
V1
医学博士
医学博士
0FCC
0FCC
0FCC
0FCC
0分
0分
0
0
0
0
0
0
0
成功
输出XML:

<ICWRRsp>
<ICWR>
    <IcwrId>379505</IcwrId>
    <WorkId>1920305</WorkId>
    <Jurisdiction>V1</Jurisdiction>
    <IcgsWc>0FCC</IcgsWc>
    <WcId>0</WcId>
</ICWR> 
<ICWR>
    <IcwrId>379505</IcwrId>
    <Jurisdiction>V1</Jurisdiction>
    <IcgsWc>0FCC</IcgsWc>
    <WcId>0</WcId>
</ICWR> 
<StatusCode>0</StatusCode>
<StatusDesc>SUCESS</StatusDesc>

379505
1920305
V1
0FCC
0
379505
V1
0FCC
0
0
成功

XSLT:


我已经编写了XSLT,但它不是迭代的。我陷入了圈套。我得到以下输出:

<?xml version="1.0" encoding="UTF-8"?>
<ICWRRsp>
   <ICWR>
      <IcwrId>379505</IcwrId>
      <WorkId>1920305</WorkId>
      <Jurisdiction>V1</Jurisdiction>
      <IcgsWc>0FCC</IcgsWc>
      <WcId>0</WcId>
   </ICWR>

 </ICWRRsp>

379505
1920305
V1
0FCC
0

有人能帮我写XSLT吗?

XML中只有一个
ICWRRsp
元素。它是根元素,因此您的
xsl:for-each
只做一件事

看起来每个
IcwrId
需要一个
ICWR
元素,因此需要选择
IcwrId
元素

<xsl:for-each select="ICWRRsp/IcwrId">
然后,为了得到其他元素,你可以这样做,例如

<WorkId><xsl:value-of select="following-sibling::WorkId[$pos]"/></WorkId>

非常感谢您,非常感谢您逐行的解释,它起作用了。:)
<xsl:variable name="pos" select="position()" />
<WorkId><xsl:value-of select="following-sibling::WorkId[$pos]"/></WorkId>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" />
    <xsl:template match="/">
        <ICWRRsp>
            <xsl:for-each select="ICWRRsp/IcwrId">
                <xsl:variable name="pos" select="position()" />
                <ICWR>
                    <IcwrId><xsl:value-of select="."/></IcwrId>
                    <WorkId><xsl:value-of select="following-sibling::WorkId[$pos]"/></WorkId>
                    <Jurisdiction><xsl:value-of select="following-sibling::Jurisdiction[$pos]"/></Jurisdiction>
                    <IcgsWc><xsl:value-of select="following-sibling::IcgsWc[$pos]"/></IcgsWc>
                    <WcId><xsl:value-of select="following-sibling::WcId[$pos]"/></WcId>
                </ICWR> 
            </xsl:for-each>             
        </ICWRRsp>
    </xsl:template>
</xsl:stylesheet>