我有以下由Tibco创建的xml消息
<?xml version="1.0" encoding="UTF-8"?>
<SalesInData>
<COMPANYID>AIN2003</COMPANYID>
<ENDDATE>20120825</ENDDATE>
<FILENAME>2-SG4_2244_20120815.xml</FILENAME>
<SalesInRecord>
<ROW_NUM>7</ROW_NUM>
<BUY_QTY>5</BUY_QTY>
<HP_PRODUCT_ID>Apj45685</HP_PRODUCT_ID>
<LOCATION_ID/>
<LOCATION_NAME>XYZ XY</LOCATION_NAME>
<UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE>
</SalesInRecord>
<STARTDATE>20120819</STARTDATE>
<SUBMITDATE>20120827</SUBMITDATE>
</SalesInData>
<?xml version="1.0" encoding="UTF-8"?>
<SalesInData>
<COMPANYID>AIN2003</COMPANYID>
<ENDDATE>20120825</ENDDATE>
<FILENAME>2-SG4_2244_20120815.xml</FILENAME>
<SalesInRecord>
<ROW_NUM>1</ROW_NUM>
<BUY_QTY>5</BUY_QTY>
<HP_PRODUCT_ID>Apj45678</HP_PRODUCT_ID>
<LOCATION_ID>2-PQL-3401</LOCATION_ID>
<LOCATION_NAME>XYZ el</LOCATION_NAME>
<UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE>
</SalesInRecord>
<STARTDATE>20120819</STARTDATE>
<SUBMITDATE>20120827</SUBMITDATE>
</SalesInData>
<?xml version="1.0" encoding="UTF-8"?>
<SalesInData>
<COMPANYID>AIN2003</COMPANYID>
<ENDDATE>20120825</ENDDATE>
<FILENAME>2-SG4_2244_20120815.xml</FILENAME>
<SalesInRecord>
<ROW_NUM>1</ROW_NUM>
<BUY_QTY>5</BUY_QTY>
<HP_PRODUCT_ID>Apj45678</HP_PRODUCT_ID>
<LOCATION_ID>2-PQL-3401</LOCATION_ID>
<LOCATION_NAME>XYZ el</LOCATION_NAME>
<UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE>
</SalesInRecord>
<STARTDATE>20120819</STARTDATE>
<SUBMITDATE>20120827</SUBMITDATE>
</SalesInData>
但预期输出将为:
<?xml version="1.0" encoding="UTF-8"?>
<SalesInData>
<COMPANYID>AIN2003</COMPANYID>
<ENDDATE>20120825</ENDDATE>
<FILENAME>2-SG4_2244_20120815.xml</FILENAME>
<SalesInRecord>
<ROW_NUM>7</ROW_NUM>
<BUY_QTY>5</BUY_QTY>
<HP_PRODUCT_ID>Apj45685</HP_PRODUCT_ID>
<LOCATION_ID/>
<LOCATION_NAME>XYZ XY</LOCATION_NAME>
<UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE>
<GOODS_RECIVED_DATE/>
</SalesInRecord>
<SalesInRecord>
<ROW_NUM>1</ROW_NUM>
<BUY_QTY>5</BUY_QTY>
<HP_PRODUCT_ID>Apj45678</HP_PRODUCT_ID>
<LOCATION_ID>2-PQL-3401</LOCATION_ID>
<LOCATION_NAME>XYZ el</LOCATION_NAME>
<UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE>
<GOODS_RECIVED_DATE/>
</SalesInRecord>
<SalesInRecord>
<ROW_NUM>1</ROW_NUM>
<BUY_QTY>5</BUY_QTY>
<HP_PRODUCT_ID>Apj45678</HP_PRODUCT_ID>
<LOCATION_ID>2-PQL-3401</LOCATION_ID>
<LOCATION_NAME>XYZ el</LOCATION_NAME>
<UNIT_BUY_PRICE>999999999</UNIT_BUY_PRICE>
<GOODS_RECIVED_DATE/>
</SalesInRecord>
<STARTDATE>20120819</STARTDATE>
<SUBMITDATE>20120827</SUBMITDATE>
</SalesInData>
但我想将使用XSLT在tibco中创建的单个xml记录转换为单个xml文档,如上所示。请提供可以执行任务的代码。还有一些其他元素可以为null。
答案 0 :(得分:1)
您的输入文件没有格式良好的XML,因此没有xslt处理器可以使用它。我看到的唯一方法是首先生成一个xml文件,然后在下一步中生成一个简单的xsl处理。
#simple bash example
sed -e 's/<?xml version="1.0" encoding="UTF-8"?>//g' YOUR_INPUT > temp.file
echo '<?xml version="1.0" encoding="UTF-8"?>' > temp2.file
echo "<MyStart>" >> temp2.file
cat temp.file >> temp2.file
echo "</MyStart>" >> temp2.file
xsltproc YOUR_STYLESHEET temp2.file > YOUR_RESULT