2013-02-05 351 views
0

我需要使用XSLT fron字段在另一個XML文件中提取xml。XSLT - 從另一個XML中獲取xml

<?xml version="1.0" encoding="UTF-8" ?> 
<ns:JDBC_SELECT xmlns:ns="namepace/nt"> 
<row> 
<KEY>19</KEY> 
<QUEUE_TYPE>2</QUEUE_TYPE> 
<EVENT_STATUS>0</EVENT_STATUS> 
<EVENT_TYPE>New Work Package Request</EVENT_TYPE> 
<CONTENT><?xml version="1.0" encoding="utf-8" standalone="yes"?><event xmlns:ns="namespace/nt" reference="0000000000" source="NBA" target="SAP" timestamp="2013-02-04T14:32:01.836+00:00" type="New Work Package Request" version="1.0" id="19"><new-work-package-request-event><work-order-id>11</work-order-id><personnel-id>ra_a</personnel-id><request-timestamp>2013-02-04T14:32:01.836+00:00</request-timestamp><new-notification-request><type>Z2</type><requirement-code>RI0D</requirement-code><main-work-centre>0102</main-work-centre><planner-group>L00</planner-group><functional-location-id>1024</functional-location-id><short-text>SET UP/REMOVE ISOLATION RUN</short-text><long-text>SET UP/REMOVE ISOLATION RUN, 1024, NORTON FOXLEY (PRV) NORTON FOXLEY Nightline Increase: (l/h)</long-text><personnel-resp-id>12157</personnel-resp-id><cost-centre>3600</cost-centre></new-notification-request><new-work-order-request><type>ZPM2</type></new-work-order-request></new-work-package-request-event></event></CONTENT> 
</row> 
</ns:JDBC_SELECT> 

<xsl:transform xmlns:xsl="namespace/nt" version="1.0"> 
    <xslutput method="xml"/> 
    <xsl:template match="/"> 
    <xsl:copy-of select="//CONTENT"/> 
    </xsl:template> 
</xsl:transform> 

但不是運氣。 有什麼想法?

+0

如何生成此XML文件? –

回答

0

的XML無效 - 它不能包含的元素內部的第二

<?xml version="1.0" encoding="utf-8"?> 

聲明。因爲它不會加載。

有一個在XSLT的問題,以及 - 命名空間必須是http://www.w3.org/1999/XSL/Transform

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:output method="xml" indent="yes"/> 

    <xsl:template match="/"> 
     <xsl:copy-of select="//CONTENT"/> 
    </xsl:template> 

</xsl:stylesheet> 

一旦你在XML擺脫第二<?xml....>聲明,上述XSLT作品,產區的輸出:

<?xml version="1.0" encoding="utf-8"?> 
<CONTENT xmlns:ns="namepace/nt"> 
    <event reference="0000000000" source="NBA" target="SAP" timestamp="2013-02-04T14:32:01.836+00:00" type="New Work Package Request" version="1.0" id="19" xmlns:ns="namespace/nt"> 
    <new-work-package-request-event> 
     <work-order-id>11</work-order-id> 
     <personnel-id>ra_a</personnel-id> 
     <request-timestamp>2013-02-04T14:32:01.836+00:00</request-timestamp> 
     <new-notification-request> 
     <type>Z2</type> 
     <requirement-code>RI0D</requirement-code> 
     <main-work-centre>0102</main-work-centre> 
     <planner-group>L00</planner-group> 
     <functional-location-id>1024</functional-location-id> 
     <short-text>SET UP/REMOVE ISOLATION RUN</short-text> 
     <long-text>SET UP/REMOVE ISOLATION RUN, 1024, NORTON FOXLEY (PRV) NORTON FOXLEY Nightline Increase: (l/h)</long-text> 
     <personnel-resp-id>12157</personnel-resp-id> 
     <cost-centre>3600</cost-centre> 
     </new-notification-request> 
     <new-work-order-request> 
     <type>ZPM2</type> 
     </new-work-order-request> 
    </new-work-package-request-event> 
    </event> 
</CONTENT> 
+0

嗨,是的,我知道,但他們發給我一個XML內的另一個,然後,我必須提取它。 它必須是一種方法,但我不知道。 – Cerbero22

+0

我不認爲你可以使用XSLT - 你必須編寫一個處理XML文本的程序,或者至少可以刪除額外的聲明,然後你可以在生成的'clean XML'上使用XSLT, – MiMo