2016-05-18 8 views
0

次の構造のXMLファイルがあります。 XMLファイルからデータを読み込み、XSLファイルを使用して別の形式に変換したいのですが、何らかの形でXMLノードを読み込んでいない場合もあります。誰かが私にそれをする方法を提案してもらえますか?ルートノードの後に​​XMLがXSLで動作しない

XMLドキュメント:

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="spss2eml.xsl"?> 
<outputTree xmlns="http://www.ibm.com/software/analytics/spss/xml/oms" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.ibm.com/software/analytics/spss/xml/oms http://www.ibm.com/software/analytics/spss/xml/oms/spss-output-1.8.xsd"> 
    <command command="Codebook" displayOutlineValues="label" displayOutlineVariables="label" 
     displayTableValues="label" displayTableVariables="label" lang="en" text="Codebook"> 
     <pivotTable subType="Variable Information" text="Respondent_Serial"> 
      <dimension axis="row" text="Attributes"> 
       <group text="Standard Attributes"> 
        <category text="Label"> 
         <dimension axis="column" text="Values"> 
          <category text="Value"> 
           <cell text="Serial number"/> 
          </category> 
         </dimension> 
        </category> 
        <category text="Type"> 
         <dimension axis="column" text="Values"> 
          <category text="Value"> 
           <cell text="Numeric"/> 
          </category> 
         </dimension> 
        </category> 
        <category text="Format"> 
         <dimension axis="column" text="Values"> 
          <category text="Value"> 
           <cell text="F10"/> 
          </category> 
         </dimension> 
        </category> 
        <category text="Measurement"> 
         <dimension axis="column" text="Values"> 
          <category text="Value"> 
           <cell text="Scale"/> 
          </category> 
         </dimension> 
        </category> 
        <category text="Role"> 
         <dimension axis="column" text="Values"> 
          <category text="Value"> 
           <cell text="Input"/> 
          </category> 
         </dimension> 
        </category> 
       </group> 
      </dimension> 
     </pivotTable> 
     <pivotTable subType="Variable Information" text="Respondent_ID"> 
      <dimension axis="row" text="Attributes"> 
       <group text="Standard Attributes"> 
        <category text="Label"> 
         <dimension axis="column" text="Values"> 
          <category text="Value"> 
           <cell text="ID"/> 
          </category> 
         </dimension> 
        </category> 
        <category text="Type"> 
         <dimension axis="column" text="Values"> 
          <category text="Value"> 
           <cell text="String"/> 
          </category> 
         </dimension> 
        </category> 
        <category text="Format"> 
         <dimension axis="column" text="Values"> 
          <category text="Value"> 
           <cell text="A150"/> 
          </category> 
         </dimension> 
        </category> 
        <category text="Measurement"> 
         <dimension axis="column" text="Values"> 
          <category text="Value"> 
           <cell text="Nominal"/> 
          </category> 
         </dimension> 
        </category> 
        <category text="Role"> 
         <dimension axis="column" text="Values"> 
          <category text="Value"> 
           <cell text="Input"/> 
          </category> 
         </dimension> 
        </category> 
       </group> 
      </dimension> 
     </pivotTable> 
    </command> 
    </outputTree> 

私のXSLスタイルシート(spss2eml.xsl):

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="xml" indent="yes"/> 
    <xsl:template match="/"> 
     <attributeList> 
      <xsl:for-each select="ns1:outputTree/ns1:command/ns1:pivotTable" 
       xmlns:ns1="http://xml.spss.com/spss/oms"> 
       <xsl:element name="attribute"> 
        <xsl:attribute name="id"> 
         <xsl:value-of select="@text"/> 
        </xsl:attribute> 
        <xsl:element name="attributeName"> 
         <xsl:value-of select="@text"/> 
        </xsl:element> 
        <xsl:element name="attributeDefinition"> 
         <xsl:value-of 
          select="ns1:dimension/ns1:group[@text='Standard Attributes']/ns1:category[@text='Label']/ns1:dimension/ns1:category/ns1:cell/@text" 
         /> 
        </xsl:element> 
        <xsl:element name="storageType"> 
         <xsl:attribute name="typeSystem" 
          >http://www.w3.org/2001/XMLSchema-datatypes</xsl:attribute> 
         <xsl:choose> 
          <xsl:when 
           test="ns1:dimension/ns1:group[@text='Standard Attributes']/ns1:category[@text='Type']/ns1:dimension/ns1:category/ns1:cell[@text='Numeric']" 
           >float</xsl:when> 
          <xsl:otherwise>string</xsl:otherwise> 
         </xsl:choose> 
        </xsl:element> 
        <xsl:element name="measurementScale"> 
         <xsl:choose> 
          <xsl:when 
           test="ns1:dimension/ns1:group[@text='Standard Attributes']/ns1:category[@text='Measurement']/ns1:dimension/ns1:category/ns1:cell[@text='Scale']">Scale        
          </xsl:when> 
          <xsl:when 
           test="ns1:dimension/ns1:group[@text='Standard Attributes']/ns1:category[@text='Measurement']/ns1:dimension/ns1:category/ns1:cell[@text='Nominal']"> 
           <nominal> 
            Nominal 
           </nominal> 
          </xsl:when> 
          <xsl:when 
           test="ns1:dimension/ns1:group[@text='Standard Attributes']/ns1:category[@text='Measurement']/ns1:dimension/ns1:category/ns1:cell[@text='Ordinal']"> 
           <ordinal> 
            Ordinal 
           </ordinal> 
          </xsl:when> 
         </xsl:choose> 
        </xsl:element> 
       </xsl:element> 
      </xsl:for-each> 
     </attributeList> 
    </xsl:template> 
</xsl:stylesheet> 

答えて

0

あなたのソースXMLを使用すると、あなたのスタイルシートで使用しているものとは異なる名前空間を使用しています。ソースXMLは、デフォルトの名前空間があります。

xmlns="http://www.ibm.com/software/analytics/spss/xml/oms" 

をしかし、あなたは定義:

xmlns:ns1="http://xml.spss.com/spss/oms" 

の代わり:

xmlns:ns1="http://www.ibm.com/software/analytics/spss/xml/oms" 

をこの変更を行うと、あなたは違いが表示されます。期待した結果を投稿していないので、実際のコードには入っていません。あなたはliteral result elementsattribute value templatesを使用することによって大幅に短縮することができること、しかし、注意してください - 例えば:私は名前空間の問題があった

<attribute id="{@text}"/> 
+0

<xsl:element name="attribute"> <xsl:attribute name="id"> <xsl:value-of select="@text"/> </xsl:attribute> </xsl:element> 

は次のように簡単に書くことができます。名前空間を修正した後でうまくいきました。ありがとう!! –

関連する問題