XML元素“row”需要通过“case”重命名,“CKEY”需要通过“key”重命名
源文件:在这种情况下,包含row和ckey的是我需要替换的XML元素,如上所述
<DST>
<PQCallHistory>
<hostAddress>$$$$$$$</hostAddress>
<hostPort>$$$$$</hostPort>
<userID>$$$$$</userID>
<password>$$$$$</password>
<folder>
<CRDATTIM>2012112302.44.40.334480</CRDATTIM>
<RECORDCD>F</RECORDCD>
<CRNODE>01</CRNODE>
<CaseCount>10</CaseCount>
<lastCRDATTIM>2014040202.23.10.105840</lastCRDATTIM>
<row>
<CRDATTIM>2014061709.58.36.947900</CRDATTIM>
<CMEDIA>Phone</CMEDIA>
<CRNODE>01</CRNODE>
<RECORDCD>C</RECORDCD>
<UNITCD>CSMHCQA</UNITCD>
<STATCD>CREATED</STATCD>
<STPTIM>2014061720.28.35.000000</STPTIM>
<CMOOD>Happy</CMOOD>
<CKEY>2014061709.58.36.947900C01</CKEY>
</row>
<row>
<CRDATTIM>2014061709.52.53.157900</CRDATTIM>
<CMEDIA>Phone</CMEDIA>
<CRNODE>01</CRNODE>
<RECORDCD>C</RECORDCD>
<UNITCD>CSMHCQA</UNITCD>
<STATCD>CREATED</STATCD>
<STPTIM>2014061720.22.51.000000</STPTIM>
<CMOOD>Happy</CMOOD>
<CKEY>2014061709.52.53.157900C01</CKEY>
</row>
<row>
<CRDATTIM>2014061605.05.44.690900</CRDATTIM>
<CMEDIA>Phone</CMEDIA>
<CRNODE>01</CRNODE>
<RECORDCD>C</RECORDCD>
<UNITCD>CSMHCQA</UNITCD>
<STATCD>CREATED</STATCD>
<STPTIM>2014061615.35.42.000000</STPTIM>
<CMOOD>Happy</CMOOD>
<CKEY>2014061605.05.44.690900C01</CKEY>
</row>
<row>
<CRDATTIM>2014061604.58.39.446900</CRDATTIM>
<CMEDIA>Phone</CMEDIA>
<CRNODE>01</CRNODE>
<RECORDCD>C</RECORDCD>
<UNITCD>CSMHCQA</UNITCD>
<STATCD>CREATED</STATCD>
<STPTIM>2014061615.28.35.000000</STPTIM>
<CMOOD>Happy</CMOOD>
<CKEY>2014061604.58.39.446900C01</CKEY>
</row>
<row>
<CRDATTIM>2014061104.03.59.807840</CRDATTIM>
<CMEDIA>Phone</CMEDIA>
<CRNODE>01</CRNODE>
<RECORDCD>C</RECORDCD>
<UNITCD>CSMHCQA</UNITCD>
<STATCD>CREATED</STATCD>
<STPTIM>2014061114.33.53.000000</STPTIM>
<CMOOD>Happy</CMOOD>
<CKEY>2014061104.03.59.807840C01</CKEY>
</row>
</folder>
</PQCallHistory>
</DST>
Expected file : This is the file, What i expected.
<PQCallHistory>
<hostAddress>$$$$$$$$</hostAddress>
<hostPort>$$$$$</hostPort>
<userID>$$$$$$$</userID>
<password>$$$$$</password>
<folder>
<CRDATTIM>2012112302.44.40.334480</CRDATTIM>
<RECORDCD>F</RECORDCD>
<CRNODE>01</CRNODE>
<CaseCount>10</CaseCount>
<lastCRDATTIM>2014040202.23.10.105840</lastCRDATTIM>
<case>
<CRDATTIM>2014052900.56.23.813840</CRDATTIM>
<CMEDIA>Phone</CMEDIA>
<CRNODE>01</CRNODE>
<RECORDCD>C</RECORDCD>
<UNITCD>CSMHCQA</UNITCD>
<STATCD>CREATED</STATCD>
<STPTIM>2014052911.26.20.000000</STPTIM>
<CMOOD>Happy</CMOOD>
<KEY>2014052900.56.23.813840C01</KEY>
</case>
<case>
<CRDATTIM>2014052208.02.59.494840</CRDATTIM>
<CMEDIA>Phone</CMEDIA>
<CRNODE>01</CRNODE>
<RECORDCD>C</RECORDCD>
<UNITCD>CSMHCQA</UNITCD>
<STATCD>CREATED</STATCD>
<STPTIM>2014052218.32.46.000000</STPTIM>
<CMOOD>Happy</CMOOD>
<KEY>2014052208.02.59.494840C01</KEY>
</case>
<case>
<CRDATTIM>2014042403.02.31.131840</CRDATTIM>
<CMEDIA>Phone</CMEDIA>
<CRNODE>01</CRNODE>
<RECORDCD>C</RECORDCD>
<UNITCD>CSMHCQA</UNITCD>
<STATCD>CREATED</STATCD>
<STPTIM>2014042413.32.23.000000</STPTIM>
<CMOOD>Happy</CMOOD>
<KEY>2014042403.02.31.131840C01</KEY>
</case>
<case>
<CRDATTIM>2014040202.24.00.823840</CRDATTIM>
<CMEDIA>Phone</CMEDIA>
<CRNODE>01</CRNODE>
<RECORDCD>C</RECORDCD>
<UNITCD>CSMHCQA</UNITCD>
<STATCD>CREATED</STATCD>
<STPTIM>2014040212.53.58.000000</STPTIM>
<CMOOD>Happy</CMOOD>
<KEY>2014040202.24.00.823840C01</KEY>
</case>
<case>
<CRDATTIM>2014040202.23.10.105840</CRDATTIM>
<CMEDIA>Phone</CMEDIA>
<CRNODE>01</CRNODE>
<RECORDCD>C</RECORDCD>
<UNITCD>CSMHCQA</UNITCD>
<STATCD>CREATED</STATCD>
<STPTIM>2014040212.53.08.000000</STPTIM>
<CMOOD>Happy</CMOOD>
<KEY>2014040202.23.10.105840C01</KEY>
</case>
</folder>
</PQCallHistory>
</DST>
任何人都能帮助我......
答案 0 :(得分:0)
使用此XSLT ..我已从您的模板中删除了xsl:copy,并且表达式包含&#34; // PQ&#34;但是输入XML中没有这样的元素:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="PQCallHistory/folder/row">
<case>
<xsl:apply-templates select="@* | node()" />
</case>
</xsl:template>
</xsl:stylesheet>