使用xsl文件将标记从一个位置移动到另一个位置

时间:2014-07-23 11:55:57

标签: xml xslt

我需要将此标记下的数据(// PQContact / input / folder [position()= 1])移动到(// temp) 将此标记下的数据(// CDGCreateTree / DST / AWD / case [position()= 1])移动到(// temp / folder)。

对于这个我已经尝试但生成了几个xsls,可以任何一个帮助这个限制到一个xsl文件来减少文件

我的输入XML

<?xml version="1.0" encoding="UTF-8"?>
<DST>
    <PQContact>
        <hostAddress>$$$$$</hostAddress> 
        <scriptHostName>$$$$$$</scriptHostName> 
        <hostPort>$$$$</hostPort> 
        <userID>$$$$</userID> 
        <password>$$$$$</password> 
        <userIP /> 
        <release>2.0.4 Sprint</release> 
        <build>QA</build> 
        <businessArea>
            <Code>CSAAQA</Code> 
            <Selected>N</Selected> 
            <Default>Y</Default> 
            <LegacySystem>Amisys</LegacySystem> 
            <LegacyLogin>ratna</LegacyLogin> 
            <LegacyPassword>ratna</LegacyPassword> 
            <OtherLogin /> 
            <OtherPassword /> 
            <AddSecurLogin /> 
            <AddSecurPassword /> 
        </businessArea>
        <defaultBA>
            <UNITCD>CSAAQA</UNITCD> 
        </defaultBA>
        <input>
            <folder>
                <CRDATTIM>2014012103.25.06.671840</CRDATTIM> 
                <RECORDCD>F</RECORDCD> 
                <CRNODE>01</CRNODE> 
                <KEY>2014012103.25.06.671840F01</KEY> 
                <UNITCD>CSAAQA</UNITCD> 
                <FOLDTYPE>MEMBER</FOLDTYPE> 
                <FOLDERID>ANTHONY1900</FOLDERID> 
                <caller>
                    <CRDATTIM>2014012103.25.07.561840</CRDATTIM> 
                    <RECORDCD>T</RECORDCD> 
                    <CRNODE>01</CRNODE> 
                    <KEY>2014012103.25.07.561840T01</KEY> 
                    <UNITCD>CSAAQA</UNITCD> 
                    <WRKTYPE>CALLER</WRKTYPE> 
                    <STATCD>CREATED</STATCD> 
                    <CFSTNAME>A</CFSTNAME> 
                    <CLSTNAME>C</CLSTNAME> 
                    <CPHONE>(584) 6468146</CPHONE> 
                    <CPHEXT /> 
                    <CRELAT /> 
                    <CALTPHN /> 
                    <CALTEXT /> 
                    <CFAXNUM /> 
                    <CEMLADR /> 
                    <CADRLN1>30 WEST DOWN TOWN STREET</CADRLN1> 
                    <CADRLN2>SUITE 101</CADRLN2> 
                    <CCITY>ROCKVILLE</CCITY> 
                    <CSTATCD>MD</CSTATCD> 
                    <CZIPCOD>20850</CZIPCOD> 
                    <CATHRIZD>Y</CATHRIZD> 
                    <LCALDAT>20140707</LCALDAT> 
                    <CORGNAM /> 
                </caller>
                <case>
                    <UNITCD>CSAAQA</UNITCD> 
                    <CALLERKEY>2014012103.25.07.561840T01</CALLERKEY> 
                    <PREVCALL>N</PREVCALL> 
                    <STRTIM>2014070700.28.41.043000</STRTIM> 
                    <STATCD>CREATED</STATCD> 
                    <issue>
                        <UNITCD>CSAAQA</UNITCD> 
                        <STATCD>CREATED</STATCD> 
                        <worklist>false</worklist> 
                        <ISSCLASS>2</ISSCLASS> 
                        <SUBJECT>Member</SUBJECT> 
                        <ISSTYP>MS Care1st Member</ISSTYP> 
                        <ISSCAT1>Demographic Change</ISSCAT1> 
                        <ISSCAT2>Adoption</ISSCAT2> 
                        <ISSCAT3 /> 
                        <ISSCAT4 /> 
                        <ISSCAT5 /> 
                        <MEMLOB>J9J8J701</MEMLOB> 
                        <STRTIM>2014070710.59.00.000000</STRTIM> 
                        <STPTIM>2014070711.04.09.000000</STPTIM> 
                        <RELCALL>CREATED</RELCALL> 
                        <RELGRP>JK212A0001</RELGRP> 
                        <RELAUTH /> 
                        <RELMEM>ANTHONY1900</RELMEM> 
                        <RELPRV>JKCCRE</RELPRV> 
                        <RELPRVTYP>PCP</RELPRVTYP> 
                        <RELCLM /> 
                        <ORIGUSERID>DT77214</ORIGUSERID> 
                        <comments>%0D%0Adoption</comments> 
                        <RELCLMBEGDOS /> 
                        <RELCLMENDDOS /> 
                        <RELAUTHBEGDOS /> 
                        <RELAUTHENDDOS /> 
                        <FOLDERID>ANTHONY1900</FOLDERID> 
                        <ISSUEID>20140707110409DT77214</ISSUEID> 
                    </issue>
                    <Member>
                        <MemNum>ANTHONY1900</MemNum> 
                        <MemLName>C</MemLName> 
                        <MemFName>A</MemFName> 
                        <MemDOB>03/03/1903</MemDOB> 
                        <HICNNumber>H</HICNNumber> 
                        MEMBER_PROTECTED 
                        <MemPhone /> 
                        <MemAddr1>30 WEST DOWN TOWN STREET</MemAddr1> 
                        <CMEDIA>Phone</CMEDIA> 
                        <FOLDTYPE>MEMBER</FOLDTYPE> 
                        <FOLDERID>ANTHONY1900</FOLDERID> 
                    </Member>
                </case>
            </folder>
        </input>
    </PQContact>
    <CDGCreateTree>
        <userID>DT77214</userID> 
        <password>Cnffjq@1</password> 
        <hostAddress>10.193.236.57</hostAddress> 
        <hostPort>12955</hostPort> 
        <DST>
            <currentJobName>PQContactComplete</currentJobName> 
            <AWD>
                <case relate="Y" id="2014072302.10.27.041900C01">
                    <id>2014072302.10.27.041900C01</id> 
                    <createTime time="Y">20140723T02:10:27:04190005:00</createTime> 
                    <businessArea>CSAAQA</businessArea> 
                    <type>CALL</type> 
                    <workStep status="CREATED" /> 
                    <status>CREATED</status> 
                    <queue>END</queue> 
                    <priority>999</priority> 
                    <priorityIncrease>0</priorityIncrease> 
                    <VIP>N</VIP> 
                    <assignedTo /> 
                    <lockedBy /> 
                    <amount>0.0000</amount> 
                    <amountType /> 
                    <suspended>N</suspended> 
                    <process>N</process> 
                    <customScreen>WRKXMPL</customScreen> 
                    <iconName /> 
                    <CKEY>2014012103.25.07.561840T01</CKEY> 
                    <CMED>Phone</CMED> 
                    <CMOO>Happy</CMOO> 
                    <FDID>ANTHONY1900</FDID> 
                    <OUID>DT77214</OUID> 
                    <PRVC>N</PRVC> 
                    <RMEM>ANTHONY1900</RMEM> 
                    <STPT>2014070711.06.43.000000</STPT> 
                    <STRT>2014070700.28.41.043000</STRT> 
                    <permission>Update</permission> 
                    <externalSystem>
                        <host /> 
                        <executable /> 
                        <parameters /> 
                        <procedure /> 
                    </externalSystem>
                    <commentsExist>N</commentsExist> 
                    <transaction relate="Y" id="2014072302.10.26.293900T01">
                        <id>2014072302.10.26.293900T01</id> 
                        <createTime time="Y">20140723T02:10:26:29390005:00</createTime> 
                        <businessArea>CSAAQA</businessArea> 
                        <type>ISSUE</type> 
                        <workStep status="TOVBR">VBR Labeling</workStep> 
                        <status>TOVBR</status> 
                        <queue>SYSTEM</queue> 
                        <priority>999</priority> 
                        <priorityIncrease>0</priorityIncrease> 
                        <VIP>N</VIP> 
                        <assignedTo>SYSTEM</assignedTo> 
                        <lockedBy>SYSTEM</lockedBy> 
                        <amount>0.0000</amount> 
                        <amountType /> 
                        <suspended>N</suspended> 
                        <process>Y</process> 
                        <customScreen>WRKXMPL</customScreen> 
                        <iconName /> 
                        <FDID>ANTHONY1900</FDID> 
                        <ICT1>Demographic Change</ICT1> 
                        <ICT2>Adoption</ICT2> 
                        <ITYP>MS Care1st Member</ITYP> 
                        <MLOB>J9J8J701</MLOB> 
                        <OUID>DT77214</OUID> 
                        <RCAL>CREATED</RCAL> 
                        <RGRP>JK212A0001</RGRP> 
                        <RMEM>ANTHONY1900</RMEM> 
                        <RPRV>JKCCRE</RPRV> 
                        <RTYP>PCP</RTYP> 
                        <SBJT>Member</SBJT> 
                        <STPT>2014070711.04.09.000000</STPT> 
                        <STRT>2014070710.59.00.000000</STRT> 
                        <UIID>20140707110409DT77214</UIID> 
                        <CFLG>2</CFLG> 
                        <permission>Update</permission> 
                        <externalSystem>
                            <host /> 
                            <executable /> 
                            <parameters /> 
                            <procedure /> 
                        </externalSystem>
                        <commentsExist>Y</commentsExist> 
                    </transaction>
                </case>
            </AWD>
        </DST>
    </CDGCreateTree>
</DST>

预期的XML是:下面是我在为上述XML数据完成操作后所期望的XML。

 <DST>
    <PQContact>
        <hostAddress>$$$$$</hostAddress> 
        <scriptHostName>$$$$$$</scriptHostName> 
        <hostPort>$$$</hostPort> 
        <userID>$$$</userID> 
        <password>$$$$$$</password> 
        <userIP /> 
        <release>2.0.4 Sprint</release> 
        <build>QA</build> 
        <businessArea>
            <Code>CSAAQA</Code> 
            <Selected>N</Selected> 
            <Default>Y</Default> 
            <LegacySystem>Amisys</LegacySystem> 
            <LegacyLogin>ratna</LegacyLogin> 
            <LegacyPassword>ratna</LegacyPassword> 
            <OtherLogin /> 
            <OtherPassword /> 
            <AddSecurLogin /> 
            <AddSecurPassword /> 
        </businessArea>
        <defaultBA>
            <UNITCD>CSAAQA</UNITCD> 
        </defaultBA>
        <input/>
    </PQContact>
    <CDGCreateTree>
        <userID>DT77214</userID> 
        <password>Cnffjq@1</password> 
        <hostAddress>10.193.236.57</hostAddress> 
        <hostPort>12955</hostPort> 
        <DST>
            <currentJobName>PQContactComplete</currentJobName> 
            <AWD/>
        </DST>
    </CDGCreateTree>
    <temp>
        <folder>
            <CRDATTIM>2014012103.25.06.671840</CRDATTIM> 
            <RECORDCD>F</RECORDCD> 
            <CRNODE>01</CRNODE> 
            <KEY>2014012103.25.06.671840F01</KEY> 
            <UNITCD>CSAAQA</UNITCD> 
            <FOLDTYPE>MEMBER</FOLDTYPE> 
            <FOLDERID>ANTHONY1900</FOLDERID> 
            <caller>
                <CRDATTIM>2014012103.25.07.561840</CRDATTIM> 
                <RECORDCD>T</RECORDCD> 
                <CRNODE>01</CRNODE> 
                <KEY>2014012103.25.07.561840T01</KEY> 
                <UNITCD>CSAAQA</UNITCD> 
                <WRKTYPE>CALLER</WRKTYPE> 
                <STATCD>CREATED</STATCD> 
                <CFSTNAME>A</CFSTNAME> 
                <CLSTNAME>C</CLSTNAME> 
                <CPHONE>(584) 6468146</CPHONE> 
                <CPHEXT /> 
                <CRELAT /> 
                <CALTPHN /> 
                <CALTEXT /> 
                <CFAXNUM /> 
                <CEMLADR /> 
                <CADRLN1>30 WEST DOWN TOWN STREET</CADRLN1> 
                <CADRLN2>SUITE 101</CADRLN2> 
                <CCITY>ROCKVILLE</CCITY> 
                <CSTATCD>MD</CSTATCD> 
                <CZIPCOD>20850</CZIPCOD> 
                <CATHRIZD>Y</CATHRIZD> 
                <LCALDAT>20140707</LCALDAT> 
                <CORGNAM /> 
            </caller>
            <case>
                <UNITCD>CSAAQA</UNITCD> 
                <CALLERKEY>2014012103.25.07.561840T01</CALLERKEY> 
                <PREVCALL>N</PREVCALL> 
                <STRTIM>2014070700.28.41.043000</STRTIM> 
                <STATCD>CREATED</STATCD> 
                <issue>
                    <UNITCD>CSAAQA</UNITCD> 
                    <STATCD>CREATED</STATCD> 
                    <worklist>false</worklist> 
                    <ISSCLASS>2</ISSCLASS> 
                    <SUBJECT>Member</SUBJECT> 
                    <ISSTYP>MS Care1st Member</ISSTYP> 
                    <ISSCAT1>Demographic Change</ISSCAT1> 
                    <ISSCAT2>Adoption</ISSCAT2> 
                    <ISSCAT3 /> 
                    <ISSCAT4 /> 
                    <ISSCAT5 /> 
                    <MEMLOB>J9J8J701</MEMLOB> 
                    <STRTIM>2014070710.59.00.000000</STRTIM> 
                    <STPTIM>2014070711.04.09.000000</STPTIM> 
                    <RELCALL>CREATED</RELCALL> 
                    <RELGRP>JK212A0001</RELGRP> 
                    <RELAUTH /> 
                    <RELMEM>ANTHONY1900</RELMEM> 
                    <RELPRV>JKCCRE</RELPRV> 
                    <RELPRVTYP>PCP</RELPRVTYP> 
                    <RELCLM /> 
                    <ORIGUSERID>DT77214</ORIGUSERID> 
                    <comments>0%20Adoption</comments> 
                    <RELCLMBEGDOS /> 
                    <RELCLMENDDOS /> 
                    <RELAUTHBEGDOS /> 
                    <RELAUTHENDDOS /> 
                    <FOLDERID>ANTHONY1900</FOLDERID> 
                    <ISSUEID>20140707110409DT77214</ISSUEID> 
                </issue>
                <Member>
                    <MemNum>ANTHONY1900</MemNum> 
                    <MemLName>C</MemLName> 
                    <MemFName>A</MemFName> 
                    <MemDOB>03/03/1903</MemDOB> 
                    <HICNNumber>H</HICNNumber> 
                    MEMBER_PROTECTED 
                    <MemPhone /> 
                    <MemAddr1>30 WEST DOWN TOWN STREET</MemAddr1> 
                    <CMEDIA>Phone</CMEDIA> 
                    <FOLDTYPE>MEMBER</FOLDTYPE> 
                    <FOLDERID>ANTHONY1900</FOLDERID> 
                </Member>
            </case>
            <case relate="Y" id="2014072302.10.27.041900C01">
                <id>2014072302.10.27.041900C01</id> 
                <createTime time="Y">20140723T02:10:27:04190005:00</createTime> 
                <businessArea>CSAAQA</businessArea> 
                <type>CALL</type> 
                <workStep status="CREATED" /> 
                <status>CREATED</status> 
                <queue>END</queue> 
                <priority>999</priority> 
                <priorityIncrease>0</priorityIncrease> 
                <VIP>N</VIP> 
                <assignedTo /> 
                <lockedBy /> 
                <amount>0.0000</amount> 
                <amountType /> 
                <suspended>N</suspended> 
                <process>N</process> 
                <customScreen>WRKXMPL</customScreen> 
                <iconName /> 
                <CKEY>2014012103.25.07.561840T01</CKEY> 
                <CMED>Phone</CMED> 
                <CMOO>Happy</CMOO> 
                <FDID>ANTHONY1900</FDID> 
                <OUID>DT77214</OUID> 
                <PRVC>N</PRVC> 
                <RMEM>ANTHONY1900</RMEM> 
                <STPT>2014070711.06.43.000000</STPT> 
                <STRT>2014070700.28.41.043000</STRT> 
                <permission>Update</permission> 
                <externalSystem>
                    <host /> 
                    <executable /> 
                    <parameters /> 
                    <procedure /> 
                </externalSystem>
                <commentsExist>N</commentsExist> 
                <transaction relate="Y" id="2014072302.10.26.293900T01">
                    <id>2014072302.10.26.293900T01</id> 
                    <createTime time="Y">20140723T02:10:26:29390005:00</createTime> 
                    <businessArea>CSAAQA</businessArea> 
                    <type>ISSUE</type> 
                    <workStep status="TOVBR">VBR Labeling</workStep> 
                    <status>TOVBR</status> 
                    <queue>SYSTEM</queue> 
                    <priority>999</priority> 
                    <priorityIncrease>0</priorityIncrease> 
                    <VIP>N</VIP> 
                    <assignedTo>SYSTEM</assignedTo> 
                    <lockedBy>SYSTEM</lockedBy> 
                    <amount>0.0000</amount> 
                    <amountType /> 
                    <suspended>N</suspended> 
                    <process>Y</process> 
                    <customScreen>WRKXMPL</customScreen> 
                    <iconName /> 
                    <FDID>ANTHONY1900</FDID> 
                    <ICT1>Demographic Change</ICT1> 
                    <ICT2>Adoption</ICT2> 
                    <ITYP>MS Care1st Member</ITYP> 
                    <MLOB>J9J8J701</MLOB> 
                    <OUID>DT77214</OUID> 
                    <RCAL>CREATED</RCAL> 
                    <RGRP>JK212A0001</RGRP> 
                    <RMEM>ANTHONY1900</RMEM> 
                    <RPRV>JKCCRE</RPRV> 
                    <RTYP>PCP</RTYP> 
                    <SBJT>Member</SBJT> 
                    <STPT>2014070711.04.09.000000</STPT> 
                    <STRT>2014070710.59.00.000000</STRT> 
                    <UIID>20140707110409DT77214</UIID> 
                    <CFLG>2</CFLG> 
                    <permission>Update</permission> 
                    <externalSystem>
                        <host /> 
                        <executable /> 
                        <parameters /> 
                        <procedure /> 
                    </externalSystem>
                    <commentsExist>Y</commentsExist> 
                </transaction>
            </case>
        </folder>
    </temp>
</DST>

1 个答案:

答案 0 :(得分:1)

在这里,我向您展示了如何过滤XML中的段的两个选项。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:output method="xml" encoding="UTF-8" indent="yes" />

    <!-- 1. Option: Choose only childs of elements -->
    <xsl:template match="PQContact">
        <xsl:copy>
            <!-- now select only the elements you want to have inside PQContact -->
            <xsl:apply-templates select="hostAddress|scriptHostName"/>
        </xsl:copy>
    </xsl:template>


    <!-- 2. Option: Filter specific elements -->
    <xsl:template match="AWD">
        <!-- Filter - just do nothing -->
    </xsl:template>  

    <!-- Copy all the rest -->
    <xsl:template match="*|text()|@*">
        <xsl:copy>
            <xsl:apply-templates select="*|text()|@*"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

这会创建以下输出:

<DST>
    <PQContact>
        <hostAddress>$$$$$</hostAddress>
        <scriptHostName>$$$$$$</scriptHostName>
    </PQContact>
    <CDGCreateTree>
        <userID>DT77214</userID> 
        <password>Cnffjq@1</password> 
        <hostAddress>10.193.236.57</hostAddress> 
        <hostPort>12955</hostPort> 
        <DST>
            <currentJobName>PQContactComplete</currentJobName> 

        </DST>
    </CDGCreateTree>
</DST>

现在,您可以继续在XML

中添加所需或已过滤的元素