2014-02-20 77 views
0

我正在使用Xignite以XML格式獲取數據。目前,我已經得到了返回此呼叫:嘗試使用XLST從XML轉換爲平面表格

<?xml version="1.0" encoding="UTF-8"?><ArrayOfFundNAV xmlns="http://www.xignite.com/services/"> 
    <FundNAV> 
    <Outcome>Success</Outcome> 
    <Identity>Request</Identity> 
    <Delay>0.016001</Delay> 
    <Security> 
     <Outcome>Success</Outcome> 
     <Delay>0</Delay> 
     <CIK>N/A</CIK> 
     <Cusip>018528513</Cusip> 
     <Symbol>ABNOX</Symbol> 
     <ISIN>US0185285139</ISIN> 
     <Valoren>10967026</Valoren> 
     <Name>Alliancebernstein Bond Inflation Strategy Class </Name> 
     <Market>FUNDS</Market> 
     <CategoryOrIndustry>Inflation-Protected Bond</CategoryOrIndustry> 
    </Security> 
    <Date>2/19/2014</Date> 
    <Last>10.72</Last> 
    <Open>10.72</Open> 
    <LastClose>10.74</LastClose> 
    <ChangeFromOpen>0</ChangeFromOpen> 
    <PercentChangeFromOpen>0</PercentChangeFromOpen> 
    <ChangeFromLastClose>-0.02</ChangeFromLastClose> 
    <PercentChangeFromLastClose>-0.186</PercentChangeFromLastClose> 
    </FundNAV> 
    <FundNAV> 
    <Outcome>Success</Outcome> 
    <Message>An NAV is not yet available for the date you requested (2/19/2014). The system looked for the closest previous closing date (6/10/2011).</Message> 
    <Delay>0</Delay> 
    <Security> 
     <Outcome>Success</Outcome> 
     <Message>This security is no longer listed.</Message> 
     <Delay>0</Delay> 
     <CIK>0000353447</CIK> 
     <Cusip>014470405</Cusip> 
     <Symbol>ABPXX</Symbol> 
     <ISIN>US0144704055</ISIN> 
     <Valoren>2824817</Valoren> 
     <Name>Cash Reserves Fd Inc. Prime Institutional Shar </Name> 
     <Market>FUNDS</Market> 
     <CategoryOrIndustry>Money Market-Taxable</CategoryOrIndustry> 
    </Security> 
    <Date>6/10/2011</Date> 
    <Last>0.01</Last> 
    <Open>0.01</Open> 
    <LastClose>0.09</LastClose> 
    <ChangeFromOpen>0</ChangeFromOpen> 
    <PercentChangeFromOpen>0</PercentChangeFromOpen> 
    <ChangeFromLastClose>-0.08</ChangeFromLastClose> 
    <PercentChangeFromLastClose>-88.889</PercentChangeFromLastClose> 
    </FundNAV> 
    <FundNAV> 
    <Outcome>Success</Outcome> 
    <Delay>0</Delay> 
    <Security> 
     <Outcome>Success</Outcome> 
     <Delay>0</Delay> 
     <CIK>0000003794</CIK> 
     <Cusip>018528612</Cusip> 
     <Symbol>ABQIX</Symbol> 
     <ISIN>US0185286129</ISIN> 
     <Valoren>2089748</Valoren> 
     <Name>Alliancebernstein Bond Fd Alliancebernstein Int </Name> 
     <Market>FUNDS</Market> 
     <CategoryOrIndustry>Intermediate-Term Bond</CategoryOrIndustry> 
    </Security> 
    <Date>2/19/2014</Date> 
    <Last>11.03</Last> 
    <Open>11.03</Open> 
    <LastClose>11.04</LastClose> 
    <ChangeFromOpen>0</ChangeFromOpen> 
    <PercentChangeFromOpen>0</PercentChangeFromOpen> 
    <ChangeFromLastClose>-0.01</ChangeFromLastClose> 
    <PercentChangeFromLastClose>-0.091</PercentChangeFromLastClose> 
    </FundNAV> 
</ArrayOfFundNAV> 

我則試圖以此來改變它:

<xslt:stylesheet xmlns:xslt="http://www.w3.org/1999/XSL/Transform" xmlns:csw-xform="http://www.compositesw.com/2003/xform" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.xignite.com/services/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"> 
    <xslt:template match="/"> 
    <xslt:variable name="_Outcome"/> 
    <xslt:variable name="_Message"/> 
    <xslt:variable name="_Identity"/> 
    <xslt:variable name="_Delay"/> 
    <xslt:variable name="_Date"/> 
    <xslt:variable name="_LastVal"/> 
    <xslt:variable name="_OpenVal"/> 
    <xslt:variable name="_LastClose"/> 
    <xslt:variable name="_ChangeFromOpen"/> 
    <xslt:variable name="_PercentChangeFromOpen"/> 
    <xslt:variable name="_ChangeFromLastClose"/> 
    <xslt:variable name="_PercentChangeFromLastClose"/> 
    <xslt:variable name="_Security_Outcome"/> 
    <xslt:variable name="_Security_Message"/> 
    <xslt:variable name="_Security_Identity"/> 
    <xslt:variable name="_Security_Delay"/> 
    <xslt:variable name="_Security_CIK"/> 
    <xslt:variable name="_Security_Cusip"/> 
    <xslt:variable name="_Security_Symbol"/> 
    <xslt:variable name="_Security_ISIN"/> 
    <xslt:variable name="_Security_Valoren"/> 
    <xslt:variable name="_Security_Name"/> 
    <xslt:variable name="_Security_Market"/> 
    <xslt:variable name="_Security_CategOrIndustry"/> 
    <xslt:element name="results"> 
     <xslt:for-each select="ns1:ArrayOfFundNAV"> 
     <xslt:for-each select="ns1:FundNAV"> 
      <xslt:variable name="_Outcome" select="ns1:Outcome"/> 
      <xslt:variable name="_Message" select="ns1:Message"/> 
      <xslt:variable name="_Identity" select="ns1:Identity"/> 
      <xslt:variable name="_Delay" select="ns1:Delay"/> 
      <xslt:variable name="_Date" select="ns1:Date"/> 
      <xslt:variable name="_LastVal" select="ns1:Last"/> 
      <xslt:variable name="_OpenVal" select="ns1:Open"/> 
      <xslt:variable name="_LastClose" select="ns1:LastClose"/> 
      <xslt:variable name="_ChangeFromOpen" select="ns1:ChangeFromOpen"/> 
      <xslt:variable name="_PercentChangeFromOpen" select="ns1:PercentChangeFromOpen"/> 
      <xslt:variable name="_ChangeFromLastClose" select="ns1:ChangeFromLastClose"/> 
      <xslt:variable name="_PercentChangeFromLastClose" select="ns1:PercentChangeFromLastClose"/> 
      <xslt:for-each select="ns1:Security"> 
      <xslt:variable name="_Security_Outcome" select="ns1:Outcome"/> 
      <xslt:variable name="_Security_Message" select="ns1:Message"/> 
      <xslt:variable name="_Security_Identity" select="ns1:Identity"/> 
      <xslt:variable name="_Security_Delay" select="ns1:Delay"/> 
      <xslt:variable name="_Security_CIK" select="ns1:CIK"/> 
      <xslt:variable name="_Security_Cusip" select="ns1:Cusip"/> 
      <xslt:variable name="_Security_Symbol" select="ns1:Symbol"/> 
      <xslt:variable name="_Security_ISIN" select="ns1:ISIN"/> 
      <xslt:variable name="_Security_Valoren" select="ns1:Valoren"/> 
      <xslt:variable name="_Security_Name" select="ns1:Name"/> 
      <xslt:variable name="_Security_Market" select="ns1:Market"/> 
      <xslt:variable name="_Security_CategOrIndustry" select="ns1:CategoryOrIndustry"/> 
      <xslt:element name="result"> 
       <xslt:element name="Outcome"> 
       <xslt:value-of select="$_Outcome"/> 
       </xslt:element> 
       <xslt:element name="Message"> 
       <xslt:value-of select="$_Message"/> 
       </xslt:element> 
       <xslt:element name="Identity"> 
       <xslt:value-of select="$_Identity"/> 
       </xslt:element> 
       <xslt:element name="Delay"> 
       <xslt:value-of select="$_Delay"/> 
       </xslt:element> 
       <xslt:element name="Date"> 
       <xslt:value-of select="$_Date"/> 
       </xslt:element> 
       <xslt:element name="LastVal"> 
       <xslt:value-of select="$_LastVal"/> 
       </xslt:element> 
       <xslt:element name="OpenVal"> 
       <xslt:value-of select="$_OpenVal"/> 
       </xslt:element> 
       <xslt:element name="LastClose"> 
       <xslt:value-of select="$_LastClose"/> 
       </xslt:element> 
       <xslt:element name="ChangeFromOpen"> 
       <xslt:value-of select="$_ChangeFromOpen"/> 
       </xslt:element> 
       <xslt:element name="PercentChangeFromOpen"> 
       <xslt:value-of select="$_PercentChangeFromOpen"/> 
       </xslt:element> 
       <xslt:element name="ChangeFromLastClose"> 
       <xslt:value-of select="$_ChangeFromLastClose"/> 
       </xslt:element> 
       <xslt:element name="PercentChangeFromLastClose"> 
       <xslt:value-of select="$_PercentChangeFromLastClose"/> 
       </xslt:element> 
       <xslt:element name="Security_Outcome"> 
       <xslt:value-of select="$_Security_Outcome"/> 
       </xslt:element> 
       <xslt:element name="Security_Message"> 
       <xslt:value-of select="$_Security_Message"/> 
       </xslt:element> 
       <xslt:element name="Security_Identity"> 
       <xslt:value-of select="$_Security_Identity"/> 
       </xslt:element> 
       <xslt:element name="Security_Delay"> 
       <xslt:value-of select="$_Security_Delay"/> 
       </xslt:element> 
       <xslt:element name="Security_CIK"> 
       <xslt:value-of select="$_Security_CIK"/> 
       </xslt:element> 
       <xslt:element name="Security_Cusip"> 
       <xslt:value-of select="$_Security_Cusip"/> 
       </xslt:element> 
       <xslt:element name="Security_Symbol"> 
       <xslt:value-of select="$_Security_Symbol"/> 
       </xslt:element> 
       <xslt:element name="Security_ISIN"> 
       <xslt:value-of select="$_Security_ISIN"/> 
       </xslt:element> 
       <xslt:element name="Security_Valoren"> 
       <xslt:value-of select="$_Security_Valoren"/> 
       </xslt:element> 
       <xslt:element name="Security_Name"> 
       <xslt:value-of select="$_Security_Name"/> 
       </xslt:element> 
       <xslt:element name="Security_Market"> 
       <xslt:value-of select="$_Security_Market"/> 
       </xslt:element> 
       <xslt:element name="Security_CategOrIndustry"> 
       <xslt:value-of select="$_Security_CategOrIndustry"/> 
       </xslt:element> 
      </xslt:element> 
      </xslt:for-each> 
     </xslt:for-each> 
     </xslt:for-each> 
    </xslt:element> 
    </xslt:template> 
</xslt:stylesheet> 

我需要怎麼做才能去除層次,只是使這樣它就像桌子一樣平坦嗎?

+2

_「我需要做些什麼來刪除層次結構,並使它像桌子一樣平整?」_沒有任何意義。請編輯您的文章,幷包含您想要從輸入中產生的樣本。 –

+0

我相信你必須爲這個問題添加一個'xslt'標籤。 –

回答

0

你會試試這個模板嗎?看看這是否符合你的要求。

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:csw-xform="http://www.compositesw.com/2003/xform" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.xignite.com/services/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"> 

    <xsl:output indent="yes"/> 

    <xsl:template match="*"> 
     <xsl:choose> 
      <xsl:when test="child::*"> 
       <xsl:apply-templates/> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:element name="{concat(parent::node()/local-name(), '_', local-name())}"> 
        <xsl:apply-templates/> 
       </xsl:element> 
      </xsl:otherwise> 
     </xsl:choose> 

    </xsl:template> 

</xsl:stylesheet> 
+0

它沒有列迴應。 輸出是這樣的: '成功' –

+0

請發表您所需的輸出XML。 –