2 Replies Latest reply on Dec 6, 2009 3:24 AM by Belton

    XSLT can you make a back-reference to an earlier node?

    Belton

      Title

      XSLT can you make a back-reference to an earlier node?

      Post

      still a relative novice, FM10, OSX10.5

       

      I hope I can explain this I might not have the right vocabulary. 

      I certainly don't fully understand XSLT syntax. 

       

      I have a set of values that can vary in each record from zero to eighteen fields

      Rather than import to a table that has eighteen fields for each record I thought it would be better to have a table I can use in relationship with one row per value.

       

      more specifically here is an edited sample of two records in the xml file

       

      <character>
      <literal>安</literal>
      <reading_meaning>
      <rmgroup>

      <reading r_type="ja_on">アン</reading>

      <reading r_type="ja_kun">やす.い</reading>
      <reading r_type="ja_kun">やす.まる</reading>
      <reading r_type="ja_kun">やす</reading>
      <reading r_type="ja_kun">やす.らか</reading>
      </rmgroup>
      </reading_meaning>
      </character>

      <character>
      <literal>庵</literal>
      <reading_meaning>
      <rmgroup>

      <reading r_type="ja_on">アン</reading>
      <reading r_type="ja_kun">いおり</reading>
      <reading r_type="ja_kun">いお</reading>
      </rmgroup>
      </reading_meaning>
      </character>

       

      The output I'd like is 6 rows 2 columns 

       

       安 : やす.い

       安 : やす.まる

       安 : やす

       安 : やす.らか

       庵 : いおり

       庵 : いお

       

      I can get 2 rows of 4 columns (which I think will be more difficult to work with later on)

       

       安 : やす.い : やす.まる : やす : やす.らか

       庵 : いおり  : いお

       

      At the moment I can get 6 rows with 2 columns BUT I can't populate the first column. 

       

         : やす.い

         : やす.まる

         : やす

         : やす.らか

         : いおり

         : いお

       

      This is the faulty code I'm trying. The reference to character/literal is obviously in the wrong place.

       

      <METADATA>

      <FIELD NAME="kanji" TYPE="TEXT" EMPTYOK="YES" MAXREPEAT=""/>
      <FIELD NAME="kunyomi" TYPE="TEXT" EMPTYOK="YES" MAXREPEAT=""/>

      </METADATA>

      <RESULTSET FOUND="">

      <xsl:for-each select="kanjidic2/character">
      <xsl:for-each select="reading_meaning/rmgroup/reading[@r_type='ja_kun']">
      <ROW MODID="" RECORDID="">
      <COL><DATA>
      <xsl:value-of select="kanjidic2/character/literal"/>
      </DATA></COL>
      <COL><DATA>
      <xsl:value-of select="." />
      </DATA></COL>
      </ROW>
      </xsl:for-each>
      </xsl:for-each>
      </RESULTSET>


       

       

      Is it possible to move it up to a correct position, store the result of select and use a reference to it later?

      or am I going in totally the wrong direction? 

       

      <xsl:for-each select="kanjidic2/character">

      <xsl:value-of select="kanjidic2/character/literal"/> how to store? ()

      <xsl:for-each select="reading_meaning/rmgroup/reading[@r_type='ja_kun']">
      <ROW MODID="" RECORDID="">
      <COL><DATA>

       a reference to the earlier value of kanjidic2/character/literal how to reference? $1

      </DATA></COL>
      <COL><DATA>
      <xsl:value-of select="." />
      </DATA></COL>
      </ROW>
      </xsl:for-each>
      </xsl:for-each>

       

       Any help would be much appreciated, thank you.






















        • 1. Re: XSLT can you make a back-reference to an earlier node?
          comment_1
            

          You can do this in two ways:

           

          Store the parent value in a variable:

           

          ... <RESULTSET FOUND=""> <xsl:for-each select="kanjidic2/character"> <xsl:variable name="lit" select="literal"/> <xsl:for-each select="reading_meaning/rmgroup/reading[@r_type='ja_kun']"> <ROW MODID="" RECORDID=""> <COL><DATA><xsl:value-of select="$lit"/></DATA></COL> <COL><DATA><xsl:value-of select="." /></DATA></COL> </ROW> </xsl:for-each> </xsl:for-each> </RESULTSET> ...

           

           Or refer directly up to the parent (or grand-grandparent, in this case):

          ... <RESULTSET FOUND=""> <xsl:for-each select="kanjidic2/character/reading_meaning/rmgroup/reading[@r_type='ja_kun']"> <ROW MODID="" RECORDID=""> <COL><DATA><xsl:value-of select="../../../literal"/></DATA></COL> <COL><DATA><xsl:value-of select="." /></DATA></COL> </ROW> </xsl:for-each> </RESULTSET> ...

           

           

           

          • 2. Re: XSLT can you make a back-reference to an earlier node?
            Belton
              

            Thank you. I really appreciate the help you give people on this forum.

             

            Both solutions work a treat.

            I can see now I didn't go far enough up the tree with my absolute reference.  doh.