This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to remove double elements????? - copying childs ofkey-referenced elements


>Date: Thu, 23 May 2002 03:55:05 EDT
>Subject: Re: [xsl] How to remove double elements????? - copying childs of key-referenced elements
>To: <jeni@jenitennison.com>
>Cc: <xsl-list@lists.mulberrytech.com>
>
>Hi Jeni, hi members
>
>sorry for responding that late, but I have been on holiday for some days.
>First I want to thank you to the fullest ;-P for your fast and competent help!!! It's amazing that you understood and solved my problem that well. After implementing some slightly changes it fits my demands perfectly. My code looks like this now:
>
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++
><!--.......................................................................-->
><!--............ define composite key for faster tool-search ..............-->
> 
> <xsl:key name="releasekey" match="release" use="concat(../@name,'#',@name)"/>
>
><!--.......................................................................--> 
><!--............... define  key for faster computer-search ................-->
> 
> <xsl:key name="computerkey" match="computer" use="@name"/>
>
>....
>....
>
><!--.......................................................................-->
><!--... get for each tool in current project the same tool in sw-file  ....-->
>
>  <xsl:variable name="tools">
>   <xsl:for-each select="tool">
>
> <!--...... get tools in current project sorted by category and name ......-->
>
>    <xsl:sort data-type="text" lang="en" select="@category"/>
>    <xsl:sort data-type="text" lang="en" select="@name"/>
>
> <!--................... build the key of current tool ....................-->
>  
>    <xsl:variable name="tool_key" select="concat(@name,'#',@version)"/>
>  
> <!--................... change context for key lookup ....................-->
>     
>    <xsl:for-each select="$sw-file">
>   
> <!--.... create new tool & copy all attributes & the matched release .....-->
>   
>     <xsl:variable name="release" select="key('releasekey',$tool_key)"/>
>    
> <!--...... avoid that the default namespace (html) is used for tool ......-->
>     
>     <tool xmlns="">
>      <xsl:copy-of select="$release/../@*"/>
>      <xsl:copy-of select="$release/../*[not(self::release)]"/>
>      <xsl:copy-of select="$release"/>
>     </tool>
>    </xsl:for-each>
>   </xsl:for-each>
>  </xsl:variable>
>
><!--.......................................................................-->
><!--.... get each computer in hw-file that belongs to current project .....-->
>
>  <xsl:variable name="computer">
>   <xsl:for-each select="$hw-file/hardware/computer">
>
> <!--........ get computer in hw-file sorted by function and name .........-->
>
>    <xsl:sort select="@function"/>
>    <xsl:sort select="@name"/>
>    <xsl:variable name="comp_sort" select="."/>
>
> <!--.... copy each computer from hw-file that is included in any tool ....-->
>
>    <xsl:for-each select="$tools">
>     <xsl:if test="key('computerkey', $comp_sort/@name)">
>      <xsl:copy-of select="$comp_sort"/>
>     </xsl:if>
>    </xsl:for-each>
>   </xsl:for-each>
>  </xsl:variable>
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>But using these constructions a new question came to my mind: is there a possibility to get a child of a "keyed" element??? The problem is, that the computer-elements in my sw-file have docu-elements as childs which the computer-elements in my hw-file don't have. Right now I only copy the computer-elements from hw-file, but I would also like to get the docu-elements and make them childs or at least siblings of the computer-elements (hw-file). I tried like 
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>...
>   <xsl:for-each select="$tools">
>     <xsl:if test="key('computerkey', $comp_sort/@name)">
>      <xsl:copy-of select="docu[@kind = 'local']"/>
>      <xsl:copy-of select="$comp_sort"/>
>     </xsl:if>
>    </xsl:for-each>
> <xsl:copy-of select="docu[@kind = 'local']"/>
>...
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>but there was no effect!! So how can I reach the childs of the computer-elements that are referenced by computerkey???
>
>Many thanks in advance and kindly regards,
>
>Stefan



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]