xsl-list
[Top] [All Lists]

Re: [xsl] inserting data from second file using key and document

2019-01-14 06:36:20
With that change it now takes 7 seconds.  Thanks for showing what I needed!!!!!

Jim Albright


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
    exclude-result-prefixes="xs"
    version="2.0">
    
    <xsl:variable name="LN" select="document('LN-PT-converted2.html')"/>
    <xsl:key name="insert" match="/html/body/p" use="@domain"/>
    <xsl:template match="Comments[parent::LEXSense[@LanguageCode='pt']]">
  <xsl:variable name="item_number" select="preceding::LEXDomain[1]"/>
      <!--  <test1><xsl:value-of select="$item_number"/></test1>
        <test2><xsl:value-of 
select="$LN/html/body/p[@domain=$item_number]"/></test2>
      -->
        <!--    <xsl:element name="Comments">
            <xsl:apply-templates 
select="$LN/html/body/p[@domain=$item_number]"/>
        </xsl:element>
      -->   
     <!--   <xsl:apply-templates 
select="$LN/html/body/p[@domain=$item_number]"/>
         -->   
        <xsl:element name="Comments">
           <xsl:apply-templates select="key('insert', $item_number, $LN)"/>
        </xsl:element>
        
    
    </xsl:template>
        
    <xsl:template match="span[@class='LNgrk']"/>
    <xsl:template match="span[@class='LNdfe']"/>
    <xsl:template match="span[@class='LNgle']"/>
    <xsl:template match="span[@class='LNill']"/>
    
    <!-- identify transform -->  
    <xsl:template match="@*|*|processing-instruction()|comment()">
        <xsl:copy>
            <xsl:apply-templates 
select="*|@*|text()|processing-instruction()|comment()"/>
        </xsl:copy>
    </xsl:template>  
    
</xsl:stylesheet>

The key function has (in XSLT 2 and later) an optional third argument to 
define/change the context document (or in general subtree) you want to search, 
as you work with two documents and in your template match nodes from one 
document but want to search a second you need e.g.

   key('insert', $item_number, $LN)

On the other hand for the key declaration it suffices to define

   <xsl:key name="insert" match="/html/body/p" use="@domain"/>
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>