Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 28th, 2010, 02:02 PM
Registered User
 
Join Date: May 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Default generate-id() cross-reference

Hello!

I'm new to XSLT but I was given working code that used original-ids to reference between the main entries and their sub-entries (which also have their own main entry). However, they want to generate new ids using generate-id(), and of current I'm not sure how to rewrite the code to do that. The end goal is for the Sub-entries to generate unique IDs and have those stored in the links from the Main entry.
Quote:
<xsl:template match="form">
<xsl:variable name="ids">
<xsl:value-of select="generate-id(.)"/>
</xsl:variable>
<xsl:variable name="oldid"> <!--Creates variable to hold originial-id-->
<xsl:value-of select="@id"/>
</xsl:variable>
<entry> <!--this is the main entry-->
<xsl:attribute name="id">
<xsl:value-of select="$ids"/> <!--creates a variable holding generated-id for use in sub entry references-->
</xsl:attribute>
<trait>
<xsl:attribute name="name"> <!--this is where the schema stores the original-id-->

<xsl:value-of select="'original-id'"/>
</xsl:attribute>
<xsl:attribute name="value"> <!--I want this to store the original-id, but so far no dough-->
<xsl:value-of select="@id"/>
</xsl:attribute>
</trait>
<xsl:apply-templates select="linguisticform | comments | featurevalue"/>
<xsl:apply-templates select="composed-of | compare">
<!--<xsl:with-param name="ids" select="$ids"/>-->
</xsl:apply-templates>
<!-- this is a call to the sub entry link (which will link to the main entry)-->
....
</entry>
The original code I call with apply-templates is here:
Quote:
<!--optional-->
<xsl:template match="composed-of">
<relation type="composed-of" ref="{composedform-link/@target}"
order="{composedform-link/@sequence}"/>
</xsl:template>

<!--WORKS!!-->
<xsl:template match="compare">
<relation type="{relation-term}" ref="{compare-link/@target}"> </relation>
<xsl:apply-templates select="certainty"/>
</xsl:template>
This is what I've edited (and do not have working)
Quote:
<!--Links words together-->
<!--<xsl:variable name="id" select="generate-id(.)"/>-->
<xsl:template match="composed-of">
<xsl:param name="ids"/>
<relation type="composed-of" ref="{$ids}"
order="{composedform-link/@sequence}"/>
</xsl:template>

<!-- Links compared words-->
<!--<xsl:variable name="id" select="generate-id(.)"/>--><!-- put this in empty line but it wasn't functioning; took out for debugging-->
<xsl:template match="compare">
<xsl:param name="ids"/>

<relation type="{relation-term}" ref="{$ids}" />
<xsl:apply-templates select="certainty"/>
</xsl:template>
Sample Output:
Quote:
<entry id="d1e52"> <!--Generates ID successfully-->
<trait name="original-id" value="6979"/>
<lexical-unit>
<form lang="bje">
<text>(tɛ)¹ hɑi⁷ ʨhəu¹</text><!--sneeze-->
</form>
</lexical-unit>
<relation type="Cognate" ref="6980"/>
<!--certainty= certain-->
<relation type="composed-of" ref="6978" order="1"/>
<!--I have code that will generate-id, use the same id as the main entry, but nothing generating a unique id that corresponds to it's own entry -->
<relation type="composed-of" ref="6974" order="2"/>
<relation type="composed-of" ref="1863" order="3"/>
......
</entry>
Based on the tutorials I've read, the mailing list archives I've accessed, and the books I've looked over the the forums I've been searching on, I think I might need two passed to generate the code: One to generate each unique ID, and one to reference the unique IDs in the <relation .. ref="unique id" ../>. However, I'm not sure to go about that or if it would solve my problem.

I've been dealing with this problem for a few days and I would really appreciate <i>any</i> help I can get!

Thank you!
 
Old May 29th, 2010, 06:51 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I think your code will do what you want if you uncomment the xsl:with-param that is currently in a comment. But that is my understanding based on reading your snippets, if you still encounter problems then consider to post minimal but complete XML input and XSLT stylesheet samples that allow us to run the code and then improve it if necessary.

Also note that instead of
Code:
<xsl:variable name="var-name">
   <xsl:value-of select="someExpression"/>
</xsl:variable>
it is simpler, shorter and usually more efficient to use
Code:
<xsl:variable name="var-name" select="someExpression"/>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
kaiLa (June 1st, 2010)
 
Old May 29th, 2010, 08:15 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Your code can also be much more compact if you use attribute value templates for attribute instead of xsl: attribute e.g.
Code:
<entry>
  <xsl:attribute name="id">
     <xsl:value-of select="$ids"/>
  </xsl:attribute>
  ...
</entry>
can be shortened to
Code:
<entry id="{$ids}">
...
</entry>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old June 4th, 2010, 12:26 PM
Registered User
 
Join Date: May 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks for the tips! I went through and made the code more concise and took out a few unnecessary things, and I finally have permission to post the code. I haven't figured out how to attach a file, so I apologize for the awfully long post, but the first file is the input file (one single entry example, parent-child-child example, and one parent-child example), the second is the xslt file, the third is the current output, and the last is the sought output. After doing some more research, I think I am going to have to do this in two passes-one to create id's for each entry, and another to cross-reference the orginal-id attribute in trait to the ref attribute in Borrowing-source, compare-to, and composed-of.

Again, any and all help is appreciated! Thanks!

Code:
<?xml version='1.0' encoding='UTF-8'?>
<lexicon xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="Field.xsd" lang="Biao Min" linguist="Biaomin User">
	<metadataFile href="xyz.xml"/>
	<form formtype="compound word" id="6979" verificationdate="2004-06-21" lang="Biao Min">
		<linguisticform>
			<unanalyzedform>(tɛ)&#xb9; hɑi⁷ ʨhəu&#xb9;</unanalyzedform>
		</linguisticform>
		<grammatical-relation relation-term="is a" pos="Verb"/>
		<gloss lang="English" value="sneeze">
			<semantic-field>sickness</semantic-field>
		</gloss>
		<compare>
			<compare-link target="6980">a ʨhiu3</compare-link>
			<relation-term>Cognate</relation-term>
			<certainty>certain</certainty>
		</compare>
		<composed-of>
			<composedform-link target="6978" sequence="1">(tɛ)</composedform-link>
		</composed-of>
		<composed-of>
			<composedform-link target="6974" sequence="2">hɑi</composedform-link>
		</composed-of>
		<composed-of>
			<composedform-link target="1863" sequence="3">ʨhəu</composedform-link>
		</composed-of>
	</form>
	<form formtype='free root' id='6978' verificationdate='2003-07-09' lang='Biao Min'>
		<linguisticform>
			<unanalyzedform>(tɛ)&#xb9;</unanalyzedform>
		</linguisticform>
		<gloss lang='English' value='?'>
		</gloss>
	</form>
	<form formtype="free root" id="2689" verificationdate="2004-05-17" lang="Iu Mien">
		<linguisticform>
			<unanalyzedform>tsuən&#xb3;</unanalyzedform>
		</linguisticform>
		<gloss lang="English" value="allow, permit"> </gloss>
	</form>
	<form formtype="free root" id="6974" verificationdate="2003-07-09" lang="Biao Min">
		<linguisticform>
			<unanalyzedform>hɑi⁷</unanalyzedform>
		</linguisticform>
		<gloss lang="English" value="?"> </gloss>
	</form>
	<form formtype="free root" id="1863" verificationdate="2004-04-05" lang="Biao Min">
		<linguisticform>
			<unanalyzedform>ʨhəu&#xb9;</unanalyzedform>
		</linguisticform>
		<grammatical-relation relation-term="is a" pos="Verb"/>
		<gloss lang="English" value="castrate, spay animals esp. pigs">
			<semantic-field>man and animals</semantic-field>
		</gloss>
		<comments>
			<notes>animals; esp. pigs</notes>
		</comments>
		<compare>
			<compare-link target="7068">ʨʰiɑo</compare-link>
			<relation-term>Borrowing Source</relation-term>
			<certainty>certain</certainty>
		</compare>
	</form>
	<form formtype="free root" id="7068" verificationdate="2004-04-05" lang="Chinese, Mandarin">
		<linguisticform>
			<unanalyzedform>ʨʰiɑo&#xb2;</unanalyzedform>
		</linguisticform>
		<orthographicform>qi&#xe1;o / 劁 / 劁</orthographicform>
		<gloss lang="English" value="castrate, spay animals"> </gloss>
	</form>
	<form formtype="compound word" id="6976" verificationdate="2004-06-21" lang="Biao Min">
		<linguisticform>
			<unanalyzedform>hɑi⁷ ~hɑi&#xb9;</unanalyzedform>
		</linguisticform>
		<grammatical-relation relation-term="is a" pos="Verb"/>
		<gloss lang="English" value="able, know, how,">
			<semantic-field>thoughts</semantic-field>
			<semantic-field>wishes</semantic-field>
		</gloss>
		<gloss lang="Chinese, Mandarin" value=" 会">
			<semantic-field>thoughts</semantic-field>
			<semantic-field>wishes</semantic-field>
		</gloss>
		<comments>
			<notes>bu5 hɑi2 teach</notes>
		</comments>
		<compare>
			<compare-link target="6977">hɑi</compare-link>
			<relation-term>Cognate</relation-term>
			<certainty>certain</certainty>
		</compare>
		<composed-of>
			<composedform-link target="6974" sequence="1">hɑi</composedform-link>
		</composed-of>
		<composed-of>
			<composedform-link target="6975" sequence="2">hɑi</composedform-link>
		</composed-of>
	</form>
	<form formtype='compound word' id='6894' verificationdate='2004-06-15' lang='Chinese, Mandarin'>
		<linguisticform>
			<unanalyzedform>bɑo</unanalyzedform>
		</linguisticform>
		<orthographicform>4,ba&#xf2; / 雹 / 雹</orthographicform>
		<gloss lang='English' value='hail'>
		</gloss>
	</form>
	<form formtype="compound word" id="6893" verificationdate="2004-06-15" lang="Biao Min">
		<linguisticform>
			<unanalyzedform>bin⁵ phɔ⁴</unanalyzedform>
		</linguisticform>
		<grammatical-relation relation-term="is a" pos="Noun"/>
		<gloss lang="English" value="hail">
			<semantic-field>weather, sky and light</semantic-field>
		</gloss>
		<comments>
			<notes>bin5 53 phɔ4Lʔ</notes>
		</comments>
		<compare>
			<compare-link target="6894">bɑo</compare-link>
			<relation-term>Borrowing Source</relation-term>
			<certainty>certain</certainty>
		</compare>
		<composed-of>
			<composedform-link target="259" sequence="1">bin</composedform-link>
		</composed-of>
		<composed-of>
			<composedform-link target="6890" sequence="2">phɔ</composedform-link>
		</composed-of>
	</form>
	<form formtype="free root" id="259" verificationdate="2002-07-23" lang="Biao Min">
		<linguisticform>
			<unanalyzedform>bin⁵</unanalyzedform>
		</linguisticform>
		<grammatical-relation relation-term="is a" pos="Noun"/>
		<gloss lang="English" value="ice, snow">
			<semantic-field>weather, sky and light</semantic-field>
		</gloss>
		<compare>
			<compare-link target="260">bwɑn</compare-link>
			<relation-term>Cognate</relation-term>
			<certainty>certain</certainty>
		</compare>
	</form>
	<form formtype="free root" id="260" verificationdate="2002-07-23" lang="Iu Mien">
		<linguisticform>
			<unanalyzedform>bwɑn⁵</unanalyzedform>
		</linguisticform>
		<gloss lang="English" value="ice, snow"> </gloss>
	</form>
	<form formtype="compound word" id="7107" verificationdate="2004-06-22" lang="Biao Min">
		<linguisticform>
			<unanalyzedform>kɑu⁵ bin⁵</unanalyzedform>
		</linguisticform>
		<grammatical-relation relation-term="is a" pos="Verb"/>
		<gloss lang="English" value="to freeze">
			<semantic-field>earth and fire</semantic-field>
		</gloss>
		<compare>
			<compare-link target="7108">kit7 buən5</compare-link>
			<relation-term>Comparison Form</relation-term>
		</compare>
		<composed-of>
			<composedform-link target="7106" sequence="1">kɑu</composedform-link>
		</composed-of>
		<composed-of>
			<composedform-link target="259" sequence="2">bin</composedform-link>
		</composed-of>
	</form>
	<form formtype="free root" id="7106" verificationdate="2003-07-15" lang="Biao Min">
		<linguisticform>
			<unanalyzedform>kɑu⁵</unanalyzedform>
		</linguisticform>
		<gloss lang="English" value="?"> </gloss>
	</form>
	<form formtype="free root" id="6890" verificationdate="2004-06-15" lang="Biao Min">
		<linguisticform>
			<unanalyzedform>phɔ⁴</unanalyzedform>
		</linguisticform>
		<grammatical-relation relation-term="is a" pos="Noun"/>
		<gloss lang="English" value="hail">
			<semantic-field>Nature and Natural Phenomena</semantic-field>
		</gloss>
		<gloss lang="English" value="hail">
			<semantic-field>Nature and Natural Phenomena</semantic-field>
			<semantic-field>weather, sky and light</semantic-field>
		</gloss>
		<compare>
			<compare-link target="6891">poʔ</compare-link>
			<relation-term>Cognate</relation-term>
			<certainty>certain</certainty>
		</compare>
		<compare>
			<compare-link target="6892">bɑo</compare-link>
			<relation-term>Borrowing Source</relation-term>
			<certainty>certain</certainty>
		</compare>
	</form>
	<form formtype="free root" id="6891" verificationdate="2004-06-15" lang="Iu Mien">
		<linguisticform>
			<unanalyzedform>poʔ⁸</unanalyzedform>
		</linguisticform>
		<gloss lang="English" value="hail"> </gloss>
	</form>
	<form formtype="free root" id="6892" verificationdate="2004-06-15" lang="Chinese, Mandarin">
		<linguisticform>
			<unanalyzedform>bɑo⁴</unanalyzedform>
		</linguisticform>
		<orthographicform>b&#xe0;o / 雹 / 雹</orthographicform>
		<gloss lang="English" value="hail"> </gloss>
	</form>
	<form formtype="compound word" id="6980" verificationdate="2004-06-21" lang="Iu Mien">
		<linguisticform>
			<unanalyzedform>a ʨhiu&#xb3;</unanalyzedform>
		</linguisticform>
		<gloss lang="English" value="sneeze"> </gloss>
	</form>
	<form formtype="word" id="6975" verificationdate="2003-07-09" lang="Biao Min">
		<linguisticform>
			<unanalyzedform>hɑi&#xb9;</unanalyzedform>
		</linguisticform>
		<gloss lang="English" value="?"> </gloss>
	</form>
	<form formtype="compound word" id="6977" verificationdate="2004-06-21" lang="Iu Mien">
		<linguisticform>
			<unanalyzedform>hɑi&#xb2;</unanalyzedform>
		</linguisticform>
		<gloss lang="English" value="able, know, how, 会"> </gloss>
	</form>
	<form formtype="compound word" id="7108" verificationdate="2004-06-22" lang="Iu Mien">
		<linguisticform>
			<unanalyzedform>kit⁷ buən⁵</unanalyzedform>
		</linguisticform>
		<gloss lang="English" value="to freeze"> </gloss>
	</form>
</lexicon>
Number 2 (XSL - I took out unnecessary parts)
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" encoding="UTF-8"/>
 <xsl:template match="/">
        <!-- Tells Oxygen where the RNG schema is (this is the same folder setting) -->
        <xsl:processing-instruction name="oxygen">
            RNGSchema="http://lego-wordlists.googlecode.com/svn/trunk/linguistlist/linguist-lift-schemas/linguist-lift.rng"
            type="xml" </xsl:processing-instruction>
        <xsl:processing-instruction name="oxygen">
            SCHSchema="http://lego-wordlists.googlecode.com/svn/trunk/linguistlist/linguist-lift-schemas/linguist-lift.sch" </xsl:processing-instruction>
        <lift version="0.13">
            <xsl:apply-templates/>
        </lift>
    </xsl:template>
 <xsl:template match="lexicon">
        <!-- Gets rid of EVERYTHING by itself -->
        <xsl:apply-templates/>
        <!-- Keeps interior info -->
    </xsl:template>
    <xsl:template match="metadataFile"/>
    <!-- Deletes item -->

    <xsl:template match="forms">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="form">
        <xsl:variable name="ids" select="generate-id(.)" />
        <xsl:variable name="oldid" select="@id" />
        <entry id="{$ids}">
            <trait name="'orginal-id'" value="{@id}" /> 
            <xsl:apply-templates select="linguisticform | comments | featurevalue"/>
            <xsl:apply-templates select="composed-of | compare"><!--
                <xsl:with-param name="ids" select="$ids"/>-->
            </xsl:apply-templates>
            <!--new--><!-- Stores definition in gloss, succesfully (multiple glosses in the same language allowed) -->
            <!--<xsl:for-each select="sense">
                <definition>
                    <xsl:for-each select="./gloss">
                        <xsl:call-template name="gloss"/>
                    </xsl:for-each>
                </definition>
            </xsl:for-each>-->
            <xsl:for-each select="entry">
                <xsl:apply-templates select="linguisticform"/>
            </xsl:for-each>
            <sense>
                <grammatical-info>
                    <xsl:attribute name="value">
                        <xsl:for-each select="grammatical-relation">
                            <xsl:call-template name="grammatical-relation"/>
                            <xsl:text>:</xsl:text>
                        </xsl:for-each>
                    </xsl:attribute>
                </grammatical-info>
                <!--        <xsl:apply-templates
                    select="*[not(self::linguisticform) and not(self::orthographicform) and not(self::compare) and not(self::composed-of) and not(self::comments) and not(self::grammatical-relation) and not(self::featurevalue)]"/>
                -->     <!--when feature value isn't listed here - pyszczy -->
                <definition>
                    <xsl:for-each select="gloss"><!-- For each <gloss> element in the original XML a <gloss> element is created in the LIFT XML -->
                        <xsl:if test="(@value!='') or (@value !=' ')">
                            <!--  Creates a new form within the definition to hold all the english glosses and another to hold all spanish glosses-->
                            <xsl:if test="(@lang != preceding-sibling::gloss[1]/@lang) or (position() = 1)">
                                <form>
                                    <xsl:attribute name="lang">
                                        <xsl:choose>
                                            <xsl:when test="@lang='Biao Min'">bje</xsl:when>
                                            <xsl:when test="@lang='Biao Mien'">bje</xsl:when>
                                            <xsl:when test="@lang='English'">eng</xsl:when>
                                            <xsl:when test="@lang='Chinese, Mandarin'">cmn</xsl:when>
                                            <xsl:when test="@lang='Iu Mien'">ium</xsl:when>
                                            <xsl:when test="@lang='Kim Mun'">mji</xsl:when>
                                            <xsl:when test="@lang='Thai'">tha</xsl:when>
                                            <xsl:when test="@lang='Hmong, Western Xiangxi'">mmr</xsl:when>
                                            <xsl:when test="@lang='Hmong, Northern Qiandong'">hea</xsl:when>
                                            <xsl:when test="@lang='Chinese, Yue'">yue</xsl:when>
                                            <xsl:when test="@lang='Chinese, Gan'">gan</xsl:when>
                                            <xsl:when test="@lang='Hmong, Northern Qiandong'">hea</xsl:when>
                                            <xsl:otherwise>ERROR</xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:attribute>
                                    <text>
                                        <!-- Okay, this whole variables section is designed to pull out all of the glosses with the same language and concatenate them together.
                                            This is done by creating a variable and filling it with the value of the gloss if it is of the same language, otherwise the variable is blank.
                                            So when the variables are concatenated, if there wasn't one of the same language or if there just wasn't another gloss, nothing is added.  -->
                                        <xsl:variable name="hedge">
                                            <xsl:if test="following-sibling::gloss[1]/@lang = @lang">
                                                <xsl:if test="following-sibling::gloss[1]/@lang = @lang">
                                                    <xsl:value-of select="normalize-space(concat(', ', following-sibling::gloss[1]/@value))"/>
                                                </xsl:if>
                                            </xsl:if>
                                        </xsl:variable>
                                        <xsl:variable name="hog">
                                            <xsl:if test="following-sibling::gloss[2]/@lang = @lang">
                                                <xsl:if test="following-sibling::gloss[2]/@lang = @lang">
                                                    <xsl:value-of select="normalize-space(concat(', ', following-sibling::gloss[2]/@value))"/>
                                                </xsl:if>
                                            </xsl:if>
                                        </xsl:variable>
                                        <xsl:variable name="love">
                                            <xsl:if test="following-sibling::gloss[3]/@lang = @lang">
                                                <xsl:if test="following-sibling::gloss[3]/@lang = @lang">
                                                    <xsl:value-of select="normalize-space(concat(', ', following-sibling::gloss[3]/@value))"/>
                                                </xsl:if>
                                            </xsl:if>
                                        </xsl:variable>
                                        <xsl:value-of select="normalize-space(concat(@value, $hedge, $hog, $love))"/>
                                    </text>
                                </form>
                            </xsl:if>
                        </xsl:if>
                    </xsl:for-each>
                </definition><!--<definition>
                    <xsl:for-each select="./gloss">
                        <xsl:call-template name="gloss"/>
                    </xsl:for-each>
                </definition>-->
            </sense>
       </entry>
    </xsl:template>

    <xsl:template name="grammatical-relation" match="grammatical-relation [@relation-term = 'is a']">
        <xsl:value-of select="@pos"/>
    </xsl:template>

    <!-- WORKS FINE-->
    <xsl:template match="featurevalue">
        <xsl:if test="not(. ='' or . = ' ')">
            <xsl:comment>featurevalue=<xsl:value-of select="."/></xsl:comment>
        </xsl:if>
    </xsl:template>

    <xsl:template match="gloss" name="gloss">
        <form>
            <xsl:attribute name="lang">
                <xsl:choose>
                    <xsl:when test="@lang='Biao Min'">bje</xsl:when>
                    <xsl:when test="@lang='Biao Mien'">bje</xsl:when>
                    <xsl:when test="@lang='English'">eng</xsl:when>
                    <xsl:when test="@lang='Chinese, Mandarin'">cmn</xsl:when>
                    <xsl:when test="@lang='Iu Mien'">ium</xsl:when>
                    <xsl:when test="@lang='Kim Mun'">mji</xsl:when>
                    <xsl:when test="@lang='Thai'">tha</xsl:when>
                    <xsl:when test="@lang='Hmong, Western Xiangxi'">mmr</xsl:when>
                    <xsl:when test="@lang='Hmong, Northern Qiandong'">hea</xsl:when>
                    <xsl:when test="@lang='Chinese, Yue'">yue</xsl:when>
                    <xsl:when test="@lang='Chinese, Gan'">gan</xsl:when>
                    <xsl:when test="@lang='Hmong, Northern Qiandong'">hea</xsl:when>
                    <xsl:otherwise>ERROR</xsl:otherwise>
                </xsl:choose>
            </xsl:attribute>
            <text select="normalize-space(@value)" />
        </form>  
      <!--  <xsl:apply-templates select="grammatical-info"/>-->
    </xsl:template>

    <!--WORKS FINE-->
    <xsl:template match="linguisticform">
        <lexical-unit> 
            <form>
                <!-- If you just use "@lang" value is null ~ must access parent's lang value (entry~>form) -->
                <xsl:attribute name="lang">
                   <xsl:choose>
                       <xsl:when test="parent::form/@lang='Biao Min'">bje</xsl:when>
                       <xsl:when test="parent::form/@lang='Biao Mien'">bje</xsl:when>
                       <xsl:when test="parent::form/@lang='English'">eng</xsl:when>
                       <xsl:when test="parent::form/@lang='Chinese, Mandarin'">cmn</xsl:when>
                       <xsl:when test="parent::form/@lang='Iu Mien'">ium</xsl:when>
                       <xsl:when test="parent::form/@lang='Kim Mun'">mji</xsl:when>
                       <xsl:when test="parent::form/@lang='Thai'">tha</xsl:when>
                       <xsl:when test="parent::form/@lang='Hmong, Western Xiangxi'">mmr</xsl:when>
                       <xsl:when test="parent::form/@lang='Hmong, Northern Qiandong'">hea</xsl:when>
                       <xsl:when test="parent::form/@lang='Chinese, Yue'">yue</xsl:when>
                       <xsl:when test="parent::form/@lang='Chinese, Gan'">gan</xsl:when>
                       <xsl:when test="parent::form/@lang='Hmong, Northern Qiandong'">hea</xsl:when>
                        <xsl:otherwise>ERROR</xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
                <text>
                    <xsl:value-of select="normalize-space(unanalyzedform)"/>
                </text>
            </form>
        </lexical-unit>
    </xsl:template>
  <xsl:template match="composed-of">
        <xsl:param name="ids"/>
        <relation type="composed-of" ref="{composedform-link/@target}"
            order="{composedform-link/@sequence}"/>
    </xsl:template>
    
    <!--WORKS!!-->
    <xsl:template match="compare"> 
        <xsl:param name="ids"/><!-- parent::form/@id-->
        <relation type="{relation-term}" ref="{compare-link/@target}"> </relation>
        <xsl:apply-templates select="certainty"/>
    </xsl:template>
   <xsl:template match="*">
        <xsl:copy-of select="self::node()"/>
    </xsl:template>
</xsl:stylesheet>
Number 3 (Current Output)
Code:
<?xml version="1.0" encoding="UTF-8"?><?oxygen RNGSchema="http://lego-wordlists.googlecode.com/svn/trunk/linguistlist/linguist-lift-schemas/linguist-lift.rng"
	type="xml" ?><?oxygen SCHSchema="http://lego-wordlists.googlecode.com/svn/trunk/linguistlist/linguist-lift-schemas/linguist-lift.sch" ?>
<lift version="0.13">
	<entry id="d1e52">
		<trait name="'orginal-id'" value="6979"/>
		<lexical-unit>
			<form lang="bje">
				<text>(tɛ)¹ hɑi⁷ ʨhəu¹</text>
			</form>
		</lexical-unit>
		<relation type="Cognate" ref="6980"/>
		<relation type="composed-of" ref="6978" order="1"/>
		<relation type="composed-of" ref="6974" order="2"/>
		<relation type="composed-of" ref="1863" order="3"/>
		<sense>
			<grammatical-info value="Verb:"/>
			<definition>
				<form lang="eng">
					<text>sneeze</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e100">
		<trait name="'orginal-id'" value="6980"/>
		<lexical-unit>
			<form lang="ium">
				<text>a ʨhiu³</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>sneeze</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e40">
		<trait name="'orginal-id'" value="6978"/>
		<lexical-unit>
			<form lang="bje">
				<text>(tɛ)¹</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>?</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e6978">
		<trait name="'orginal-id'" value="2689"/>
		<lexical-unit>
			<form lang="ium">
				<text>tsuən³</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>allow, permit</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e20393">
		<trait name="'orginal-id'" value="6974"/>
		<lexical-unit>
			<form lang="bje">
				<text>hɑi⁷</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>?</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e83772">
		<trait name="'orginal-id'" value="7068"/>
		<lexical-unit>
			<form lang="cmn">
				<text>ʨʰiɑo²</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>castrate, spay animals</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e20405">
		<trait name="'orginal-id'" value="6975"/>
		<lexical-unit>
			<form lang="bje">
				<text>hɑi¹</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>?</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e20532">
		<trait name="'orginal-id'" value="6977"/>
		<lexical-unit>
			<form lang="ium">
				<text>hɑi²</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>able, know, how, 会</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e20472">
		<trait name="'orginal-id'" value="6976"/>
		<lexical-unit>
			<form lang="bje">
				<text>hɑi⁷ ~hɑi¹</text>
			</form>
		</lexical-unit>
		<note>
			<form lang="eng">
				<text>bu5 hɑi2 teach</text>
			</form>
		</note>
		<relation type="Cognate" ref="6977"/>
		<relation type="composed-of" ref="6974" order="1"/>
		<relation type="composed-of" ref="6975" order="2"/>
		<sense>
			<grammatical-info value="Verb:"/>
			<definition>
				<form lang="eng">
					<text>able, know, how,</text>
				</form>
				<form lang="cmn">
					<text>会</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e83737">
		<trait name="'orginal-id'" value="1863"/>
		<lexical-unit>
			<form lang="bje">
				<text>ʨhəu¹</text>
			</form>
		</lexical-unit>
		<note>
			<form lang="eng">
				<text>animals; esp. pigs</text>
			</form>
		</note>
		<relation type="Borrowing Source" ref="7068"/>
		<sense>
			<grammatical-info value="Verb:"/>
			<definition>
				<form lang="eng">
					<text>castrate, spay animals esp. pigs</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e304">
		<trait name="'orginal-id'" value="6893"/>
		<lexical-unit>
			<form lang="bje">
				<text>bin⁵ phɔ⁴</text>
			</form>
		</lexical-unit>
		<note>
			<form lang="eng">
				<text>bin5 53 phɔ4Lʔ</text>
			</form>
		</note>
		<relation type="Borrowing Source" ref="6894"/>
		<relation type="composed-of" ref="259" order="1"/>
		<relation type="composed-of" ref="6890" order="2"/>
		<sense>
			<grammatical-info value="Noun:"/>
			<definition>
				<form lang="eng">
					<text>hail</text>
				</form>
			</definition>
		</sense>

	</entry>
	<entry id="d1e240">
		<trait name="'orginal-id'" value="259"/>
		<lexical-unit>
			<form lang="bje">
				<text>bin⁵</text>
			</form>
		</lexical-unit>
		<relation type="Cognate" ref="260"/>
		<sense>
			<grammatical-info value="Noun:"/>
			<definition>
				<form lang="eng">
					<text>ice, snow</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e269">
		<trait name="'orginal-id'" value="260"/>
		<lexical-unit>
			<form lang="ium">
				<text>bwɑn⁵</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>ice, snow</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e35457">
		<trait name="'orginal-id'" value="7107"/>
		<lexical-unit>
			<form lang="bje">
				<text>kɑu⁵ bin⁵</text>
			</form>
		</lexical-unit>
		<relation type="Comparison Form" ref="7108"/>
		<relation type="composed-of" ref="7106" order="1"/>
		<relation type="composed-of" ref="259" order="2"/>
		<sense>
			<grammatical-info value="Verb:"/>
			<definition>
				<form lang="eng">
					<text>to freeze</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e35497">
		<trait name="'orginal-id'" value="7108"/>
		<lexical-unit>
			<form lang="ium">
				<text>kit⁷ buən⁵</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>to freeze</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e35298">
		<trait name="'orginal-id'" value="7106"/>
		<lexical-unit>
			<form lang="bje">
				<text>kɑu⁵</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>?</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e48061">
		<trait name="'orginal-id'" value="6890"/>
		<lexical-unit>
			<form lang="bje">
				<text>phɔ⁴</text>
			</form>
		</lexical-unit>
		<relation type="Cognate" ref="6891"/>
		<relation type="Borrowing Source" ref="6892"/>
		<sense>
			<grammatical-info value="Noun:"/>
			<definition>
				<form lang="eng">
					<text>hail, hail</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e352">
		<trait name="'orginal-id'" value="6894"/>
		<lexical-unit>
			<form lang="cmn">
				<text>bɑo</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>hail</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e48112">
		<trait name="'orginal-id'" value="6891"/>
		<lexical-unit>
			<form lang="ium">
				<text>poʔ⁸</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>hail</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e48124">
		<trait name="'orginal-id'" value="6892"/>
		<lexical-unit>
			<form lang="cmn">
				<text>bɑo⁴</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>hail</text>
				</form>
			</definition>
		</sense>
	</entry>
</lift>
Number 4: Wanted Output
Code:
<?xml version="1.0" encoding="UTF-8"?><?oxygen RNGSchema="http://lego-wordlists.googlecode.com/svn/trunk/linguistlist/linguist-lift-schemas/linguist-lift.rng"
	type="xml" ?><?oxygen SCHSchema="http://lego-wordlists.googlecode.com/svn/trunk/linguistlist/linguist-lift-schemas/linguist-lift.sch" ?>
<lift version="0.13">
	<entry id="d1e52">
		<trait name="'orginal-id'" value="6979"/>
		<lexical-unit>
			<form lang="bje">
				<text>(tɛ)¹ hɑi⁷ ʨhəu¹</text>
			</form>
		</lexical-unit>
		<relation type="Cognate" ref="d1e100"/>
		<relation type="composed-of" ref="d1e40" order="1"/>
		<relation type="composed-of" ref="d1e20393" order="2"/>
		<relation type="composed-of" ref="d1e83737" order="3"/>
		<sense>
			<grammatical-info value="Verb:"/>
			<definition>
				<form lang="eng">
					<text>sneeze</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e100">
		<trait name="'orginal-id'" value="6980"/>
		<lexical-unit>
			<form lang="ium">
				<text>a ʨhiu³</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>sneeze</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e40">
		<trait name="'orginal-id'" value="6978"/>
		<lexical-unit>
			<form lang="bje">
				<text>(tɛ)¹</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>?</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e6978">
		<trait name="'orginal-id'" value="2689"/>
		<lexical-unit>
			<form lang="ium">
				<text>tsuən³</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>allow, permit</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e20393">
		<trait name="'orginal-id'" value="6974"/>
		<lexical-unit>
			<form lang="bje">
				<text>hɑi⁷</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>?</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e83772">
		<trait name="'orginal-id'" value="7068"/>
		<lexical-unit>
			<form lang="cmn">
				<text>ʨʰiɑo²</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>castrate, spay animals</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e20405">
		<trait name="'orginal-id'" value="6975"/>
		<lexical-unit>
			<form lang="bje">
				<text>hɑi¹</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>?</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e20532">
		<trait name="'orginal-id'" value="6977"/>
		<lexical-unit>
			<form lang="ium">
				<text>hɑi²</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>able, know, how, 会</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e20472">
		<trait name="'orginal-id'" value="6976"/>
		<lexical-unit>
			<form lang="bje">
				<text>hɑi⁷ ~hɑi¹</text>
			</form>
		</lexical-unit>
		<note>
			<form lang="eng">
				<text>bu5 hɑi2 teach</text>
			</form>
		</note>
		<relation type="Cognate" ref="d1e20532"/>
		<relation type="composed-of" ref="d1e20393" order="1"/>
		<relation type="composed-of" ref="d1e20405" order="2"/>
		<sense>
			<grammatical-info value="Verb:"/>
			<definition>
				<form lang="eng">
					<text>able, know, how,</text>
				</form>
				<form lang="cmn">
					<text>会</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e83737">
		<trait name="'orginal-id'" value="1863"/>
		<lexical-unit>
			<form lang="bje">
				<text>ʨhəu¹</text>
			</form>
		</lexical-unit>
		<note>
			<form lang="eng">
				<text>animals; esp. pigs</text>
			</form>
		</note>
		<relation type="Borrowing Source" ref="d1e83772"/>
		<sense>
			<grammatical-info value="Verb:"/>
			<definition>
				<form lang="eng">
					<text>castrate, spay animals esp. pigs</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e304">
		<trait name="'orginal-id'" value="6893"/>
		<lexical-unit>
			<form lang="bje">
				<text>bin⁵ phɔ⁴</text>
			</form>
		</lexical-unit>
		<note>
			<form lang="eng">
				<text>bin5 53 phɔ4Lʔ</text>
			</form>
		</note>
		<relation type="Borrowing Source" ref="d1e352"/>
		<relation type="composed-of" ref="d1e240" order="1"/>
		<relation type="composed-of" ref="d1e48061" order="2"/>
		<sense>
			<grammatical-info value="Noun:"/>
			<definition>
				<form lang="eng">
					<text>hail</text>
				</form>
			</definition>
		</sense>

	</entry>
	<entry id="d1e240">
		<trait name="'orginal-id'" value="259"/>
		<lexical-unit>
			<form lang="bje">
				<text>bin⁵</text>
			</form>
		</lexical-unit>
		<relation type="Cognate" ref="d1e269"/>
		<sense>
			<grammatical-info value="Noun:"/>
			<definition>
				<form lang="eng">
					<text>ice, snow</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e269">
		<trait name="'orginal-id'" value="260"/>
		<lexical-unit>
			<form lang="ium">
				<text>bwɑn⁵</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>ice, snow</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e35457">
		<trait name="'orginal-id'" value="7107"/>
		<lexical-unit>
			<form lang="bje">
				<text>kɑu⁵ bin⁵</text>
			</form>
		</lexical-unit>
		<relation type="Comparison Form" ref="d1e35497"/>
		<relation type="composed-of" ref="d1e35298" order="1"/>
		<relation type="composed-of" ref="d1e240" order="2"/>
		<sense>
			<grammatical-info value="Verb:"/>
			<definition>
				<form lang="eng">
					<text>to freeze</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e35497">
		<trait name="'orginal-id'" value="7108"/>
		<lexical-unit>
			<form lang="ium">
				<text>kit⁷ buən⁵</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>to freeze</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e35298">
		<trait name="'orginal-id'" value="7106"/>
		<lexical-unit>
			<form lang="bje">
				<text>kɑu⁵</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>?</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e48061">
		<trait name="'orginal-id'" value="6890"/>
		<lexical-unit>
			<form lang="bje">
				<text>phɔ⁴</text>
			</form>
		</lexical-unit>
		<relation type="Cognate" ref="d1e48112"/>
		<relation type="Borrowing Source" ref="d1e48124"/>
		<sense>
			<grammatical-info value="Noun:"/>
			<definition>
				<form lang="eng">
					<text>hail, hail</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e352">
		<trait name="'orginal-id'" value="6894"/>
		<lexical-unit>
			<form lang="cmn">
				<text>bɑo</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>hail</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e48112">
		<trait name="'orginal-id'" value="6891"/>
		<lexical-unit>
			<form lang="ium">
				<text>poʔ⁸</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>hail</text>
				</form>
			</definition>
		</sense>
	</entry>
	<entry id="d1e48124">
		<trait name="'orginal-id'" value="6892"/>
		<lexical-unit>
			<form lang="cmn">
				<text>bɑo⁴</text>
			</form>
		</lexical-unit>
		<sense>
			<grammatical-info value=""/>
			<definition>
				<form lang="eng">
					<text>hail</text>
				</form>
			</definition>
		</sense>
	</entry>
</lift>
 
Old June 5th, 2010, 07:47 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

With the cross-references you have in your input XML I think it is best to define a key with xsl:key that indexes the "form" elements by their original "id" attribute value and to then make use of the XSLT "key" function to find the "form" referenced by any "target" attribute. Then you can simply call generate-id on anything the "key" function returns. Thus your XSLT could be changed as follows:
Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
    <xsl:strip-space elements="*"/>
    
    <xsl:key name="form-by-id" match="form" use="@id"/>
    
 <xsl:template match="/">
        <!-- Tells Oxygen where the RNG schema is (this is the same folder setting) -->
        <xsl:processing-instruction name="oxygen">
            RNGSchema="http://lego-wordlists.googlecode.com/svn/trunk/linguistlist/linguist-lift-schemas/linguist-lift.rng"
            type="xml" </xsl:processing-instruction>
        <xsl:processing-instruction name="oxygen">
            SCHSchema="http://lego-wordlists.googlecode.com/svn/trunk/linguistlist/linguist-lift-schemas/linguist-lift.sch" </xsl:processing-instruction>
        <lift version="0.13">
            <xsl:apply-templates/>
        </lift>
    </xsl:template>
 <xsl:template match="lexicon">
        <!-- Gets rid of EVERYTHING by itself -->
        <xsl:apply-templates/>
        <!-- Keeps interior info -->
    </xsl:template>
    <xsl:template match="metadataFile"/>
    <!-- Deletes item -->

    <xsl:template match="forms">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="form">
        <xsl:variable name="ids" select="generate-id(.)" />
        <xsl:variable name="oldid" select="@id" />
        <entry id="{$ids}">
            <trait name="'orginal-id'" value="{@id}" /> 
            <xsl:apply-templates select="linguisticform | comments | featurevalue"/>
            <xsl:apply-templates select="composed-of | compare"/>
            <!--new--><!-- Stores definition in gloss, succesfully (multiple glosses in the same language allowed) -->
            <!--<xsl:for-each select="sense">
                <definition>
                    <xsl:for-each select="./gloss">
                        <xsl:call-template name="gloss"/>
                    </xsl:for-each>
                </definition>
            </xsl:for-each>-->
            <xsl:for-each select="entry">
                <xsl:apply-templates select="linguisticform"/>
            </xsl:for-each>
            <sense>
                <grammatical-info>
                    <xsl:attribute name="value">
                        <xsl:for-each select="grammatical-relation">
                            <xsl:call-template name="grammatical-relation"/>
                            <xsl:text>:</xsl:text>
                        </xsl:for-each>
                    </xsl:attribute>
                </grammatical-info>
                <!--        <xsl:apply-templates
                    select="*[not(self::linguisticform) and not(self::orthographicform) and not(self::compare) and not(self::composed-of) and not(self::comments) and not(self::grammatical-relation) and not(self::featurevalue)]"/>
                -->     <!--when feature value isn't listed here - pyszczy -->
                <definition>
                    <xsl:for-each select="gloss"><!-- For each <gloss> element in the original XML a <gloss> element is created in the LIFT XML -->
                        <xsl:if test="(@value!='') or (@value !=' ')">
                            <!--  Creates a new form within the definition to hold all the english glosses and another to hold all spanish glosses-->
                            <xsl:if test="(@lang != preceding-sibling::gloss[1]/@lang) or (position() = 1)">
                                <form>
                                    <xsl:attribute name="lang">
                                        <xsl:choose>
                                            <xsl:when test="@lang='Biao Min'">bje</xsl:when>
                                            <xsl:when test="@lang='Biao Mien'">bje</xsl:when>
                                            <xsl:when test="@lang='English'">eng</xsl:when>
                                            <xsl:when test="@lang='Chinese, Mandarin'">cmn</xsl:when>
                                            <xsl:when test="@lang='Iu Mien'">ium</xsl:when>
                                            <xsl:when test="@lang='Kim Mun'">mji</xsl:when>
                                            <xsl:when test="@lang='Thai'">tha</xsl:when>
                                            <xsl:when test="@lang='Hmong, Western Xiangxi'">mmr</xsl:when>
                                            <xsl:when test="@lang='Hmong, Northern Qiandong'">hea</xsl:when>
                                            <xsl:when test="@lang='Chinese, Yue'">yue</xsl:when>
                                            <xsl:when test="@lang='Chinese, Gan'">gan</xsl:when>
                                            <xsl:when test="@lang='Hmong, Northern Qiandong'">hea</xsl:when>
                                            <xsl:otherwise>ERROR</xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:attribute>
                                    <text>
                                        <!-- Okay, this whole variables section is designed to pull out all of the glosses with the same language and concatenate them together.
                                            This is done by creating a variable and filling it with the value of the gloss if it is of the same language, otherwise the variable is blank.
                                            So when the variables are concatenated, if there wasn't one of the same language or if there just wasn't another gloss, nothing is added.  -->
                                        <xsl:variable name="hedge">
                                            <xsl:if test="following-sibling::gloss[1]/@lang = @lang">
                                                <xsl:if test="following-sibling::gloss[1]/@lang = @lang">
                                                    <xsl:value-of select="normalize-space(concat(', ', following-sibling::gloss[1]/@value))"/>
                                                </xsl:if>
                                            </xsl:if>
                                        </xsl:variable>
                                        <xsl:variable name="hog">
                                            <xsl:if test="following-sibling::gloss[2]/@lang = @lang">
                                                <xsl:if test="following-sibling::gloss[2]/@lang = @lang">
                                                    <xsl:value-of select="normalize-space(concat(', ', following-sibling::gloss[2]/@value))"/>
                                                </xsl:if>
                                            </xsl:if>
                                        </xsl:variable>
                                        <xsl:variable name="love">
                                            <xsl:if test="following-sibling::gloss[3]/@lang = @lang">
                                                <xsl:if test="following-sibling::gloss[3]/@lang = @lang">
                                                    <xsl:value-of select="normalize-space(concat(', ', following-sibling::gloss[3]/@value))"/>
                                                </xsl:if>
                                            </xsl:if>
                                        </xsl:variable>
                                        <xsl:value-of select="normalize-space(concat(@value, $hedge, $hog, $love))"/>
                                    </text>
                                </form>
                            </xsl:if>
                        </xsl:if>
                    </xsl:for-each>
                </definition><!--<definition>
                    <xsl:for-each select="./gloss">
                        <xsl:call-template name="gloss"/>
                    </xsl:for-each>
                </definition>-->
            </sense>
       </entry>
    </xsl:template>

    <xsl:template name="grammatical-relation" match="grammatical-relation [@relation-term = 'is a']">
        <xsl:value-of select="@pos"/>
    </xsl:template>

    <!-- WORKS FINE-->
    <xsl:template match="featurevalue">
        <xsl:if test="not(. ='' or . = ' ')">
            <xsl:comment>featurevalue=<xsl:value-of select="."/></xsl:comment>
        </xsl:if>
    </xsl:template>

    <xsl:template match="gloss" name="gloss">
        <form>
            <xsl:attribute name="lang">
                <xsl:choose>
                    <xsl:when test="@lang='Biao Min'">bje</xsl:when>
                    <xsl:when test="@lang='Biao Mien'">bje</xsl:when>
                    <xsl:when test="@lang='English'">eng</xsl:when>
                    <xsl:when test="@lang='Chinese, Mandarin'">cmn</xsl:when>
                    <xsl:when test="@lang='Iu Mien'">ium</xsl:when>
                    <xsl:when test="@lang='Kim Mun'">mji</xsl:when>
                    <xsl:when test="@lang='Thai'">tha</xsl:when>
                    <xsl:when test="@lang='Hmong, Western Xiangxi'">mmr</xsl:when>
                    <xsl:when test="@lang='Hmong, Northern Qiandong'">hea</xsl:when>
                    <xsl:when test="@lang='Chinese, Yue'">yue</xsl:when>
                    <xsl:when test="@lang='Chinese, Gan'">gan</xsl:when>
                    <xsl:when test="@lang='Hmong, Northern Qiandong'">hea</xsl:when>
                    <xsl:otherwise>ERROR</xsl:otherwise>
                </xsl:choose>
            </xsl:attribute>
            <text select="normalize-space(@value)" />
        </form>  
      <!--  <xsl:apply-templates select="grammatical-info"/>-->
    </xsl:template>

    <!--WORKS FINE-->
    <xsl:template match="linguisticform">
        <lexical-unit> 
            <form>
                <!-- If you just use "@lang" value is null ~ must access parent's lang value (entry~>form) -->
                <xsl:attribute name="lang">
                   <xsl:choose>
                       <xsl:when test="parent::form/@lang='Biao Min'">bje</xsl:when>
                       <xsl:when test="parent::form/@lang='Biao Mien'">bje</xsl:when>
                       <xsl:when test="parent::form/@lang='English'">eng</xsl:when>
                       <xsl:when test="parent::form/@lang='Chinese, Mandarin'">cmn</xsl:when>
                       <xsl:when test="parent::form/@lang='Iu Mien'">ium</xsl:when>
                       <xsl:when test="parent::form/@lang='Kim Mun'">mji</xsl:when>
                       <xsl:when test="parent::form/@lang='Thai'">tha</xsl:when>
                       <xsl:when test="parent::form/@lang='Hmong, Western Xiangxi'">mmr</xsl:when>
                       <xsl:when test="parent::form/@lang='Hmong, Northern Qiandong'">hea</xsl:when>
                       <xsl:when test="parent::form/@lang='Chinese, Yue'">yue</xsl:when>
                       <xsl:when test="parent::form/@lang='Chinese, Gan'">gan</xsl:when>
                       <xsl:when test="parent::form/@lang='Hmong, Northern Qiandong'">hea</xsl:when>
                        <xsl:otherwise>ERROR</xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
                <text>
                    <xsl:value-of select="normalize-space(unanalyzedform)"/>
                </text>
            </form>
        </lexical-unit>
    </xsl:template>
  <xsl:template match="composed-of">
        <relation type="composed-of" ref="{generate-id(key('form-by-id', composedform-link/@target))}"
            order="{composedform-link/@sequence}"/>
    </xsl:template>
    
    <!--WORKS!!-->
    <xsl:template match="compare"> 
        <relation type="{relation-term}" ref="{generate-id(key('form-by-id', compare-link/@target))}"> </relation>
        <xsl:apply-templates select="certainty"/>
    </xsl:template>
   <xsl:template match="*">
        <xsl:copy-of select="self::node()"/>
    </xsl:template>
</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
kaiLa (June 7th, 2010)
 
Old June 7th, 2010, 12:55 PM
Registered User
 
Join Date: May 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Thumbs up

Thank you so much! It works exactly as it need to! :D
I am not familar with <xsl:key> ; I will have to look into that in more detail for future reference. Again, thanks!





Similar Threads
Thread Thread Starter Forum Replies Last Post
generate unique id capri SQL Server 2000 1 April 6th, 2008 10:18 AM
generate id grouping using xslt meetnaveen4u XSLT 0 May 23rd, 2005 05:14 AM
Generate-id problem. meetnaveen4u XSLT 2 May 13th, 2005 12:06 AM
How to Auto Generate ID (Primary Key) SQL database havering SQL Server 2000 9 December 1st, 2004 10:38 AM
Generate unique ID when populating a table sroman SQL Server 2000 2 August 5th, 2003 03:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.