2017-04-02 10 views
0

子が複数の値を持つときに複数のレコードを作成する。XSLT-1.0:子ノードに複数の値があるときに複数のレコードを作成する

私は、親ノードと子ノードを持つXMLを持っています。子ノードには複数の値があります。私は、タグが出力(希望)に表示される順序になるように、各子ノードごとに個別のレコードを作成しようとしています。

私のXML入力は次のとおりです。

<?xml version='1.0'?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/Records"> 
     <xsl:for-each select="Record"> 
      <ArcherRecord> 
       <AppCode> 
        <xsl:value-of select="Field" /> 
       </AppCode> 
       <xsl:for-each select="Field/Reference"> 
        <Location> 
         <xsl:value-of select="." /> 
        </Location> 
       </xsl:for-each> 
      </ArcherRecord> 
     </xsl:for-each> 
    </xsl:template> 
</xsl:stylesheet> 

しかし、私が得た出力は次のとおりです:私が試した

<Records count="65"> 
    <Record contentId="781435" levelId="17" levelGuid="33fceb92-9ee6-458f-81f6-5bd28e4af22e" moduleId="70" parentId="0"> 
    <Field id="15941" guid="75b528ad-2e19-42d6-9512-87b92bbf84d0" type="1">SPH0</Field> 
    <Field id="15997" guid="90507e16-35a1-407e-8b27-586e3e091ac3" type="9"> 
     <Reference id="409826">Alberta</Reference> 
    </Field> 
    </Record> 
    <Record contentId="783299" levelId="17" levelGuid="33fceb92-9ee6-458f-81f6-5bd28e4af22e" moduleId="70" parentId="0"> 
    <Field id="15941" guid="75b528ad-2e19-42d6-9512-87b92bbf84d0" type="1">SQV0</Field> 
    <Field id="15997" guid="90507e16-35a1-407e-8b27-586e3e091ac3" type="9"> 
     <Reference id="409187">Ontario</Reference> 
     <Reference id="409826">Quebec</Reference> 
    </Field> 
    </Record> 
</Records> 

私のXSLTコードがある

<ArcherRecord> 
    <AppCode>SPH0</AppCode> 
    <Location>Alberta</Location> 
</ArcherRecord> 

<ArcherRecord> 
    <AppCode>SQV0</AppCode> 
    <Location>Ontario</Location> 
    <Location>Quebec</Location> 
</ArcherRecord> 

の代わりに、出力Iこのような欲望:

<?xml version="1.0" encoding="UTF-8"?> 
<ArcherRecord> 
    <AppCode>SPH0</AppCode> 
    <Location>Alberta</Location> 
</ArcherRecord> 

<ArcherRecord> 
    <AppCode>SQV0</AppCode> 
    <Location>Ontario</Location> 
</ArcherRecord> 

<ArcherRecord> 
    <AppCode>SQV0</AppCode> 
    <Location>Quebec</Location> 
</ArcherRecord> 

答えて

0

これを試してください:

<?xml version='1.0'?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/Records"> 
     <xsl:for-each select="Record/Field/Reference"> 
      <ArcherRecord> 
       <AppCode> 
        <xsl:value-of select="../../Field[@type='1']" /> 
       </AppCode>      
        <Location> 
         <xsl:value-of select="." /> 
        </Location>      
      </ArcherRecord> 
     </xsl:for-each> 
    </xsl:template> 
</xsl:stylesheet> 

出力は次のようになります。

<ArcherRecord> 
    <AppCode>SPH0</AppCode> 
    <Location>Alberta</Location> 
</ArcherRecord> 
<ArcherRecord> 
    <AppCode>SQV0</AppCode> 
    <Location>Ontario</Location> 
</ArcherRecord> 
<ArcherRecord> 
    <AppCode>SQV0</AppCode> 
    <Location>Quebec</Location> 
</ArcherRecord> 
+0

おかげPavan..Thisは私が探しています正確に何です。助けてくれてありがとう – Kumar

+0

助けてくれて嬉しいです。この答えがあなたの問題を解決したら、答えの横にあるチェックマークをクリックして、それを合格とマークしてください。参照:回答の受け入れはどのように機能しますか?詳細については。 – Naidu

関連する問題