Subject: Re: [xsl] correct use of keys? From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx> Date: Wed, 12 Sep 2001 10:34:43 -0400 |
Change the node()[contains(name(), 'field')] to * [contains(name(), 'field')] if you don't need to check atribute names. Get rid of the "//" in the keys match attributes. Then I suggest that you temporarily change the stylesheet so it outputs only one node where it has to use one of the keys, and see how long it takes. This will check whether compiling the stylesheet and building the key indices is taking an inordinately long time. Another thing is whether you are testing out the transfomation in an environment where the result is displayed in a browser (like XML Cooktop or XML Spy). If so, most of the time will probably be the browser trying to display the results, not the transformation per se. For example, I have a stylesheet that transforms a 4 MB xml file down to a 400 KB xml file, and it takes some 20-30 seconds including display, but from the command line (no display) it only takes six seconds to transform with Saxon.(on a 450 MHz Pentium 3, Win98 machine). After all this, and if especially you can narrow down any particular parts of the stylesheet that are particularly slow, check back with the list. Cheers, Tom P [Kevin Burges] > > I have a stylesheet which, when run on a 10MB doc turns it into a 30MB > doc in ~600 seconds. > > Even for such a large doc, this seems like along time given my machine > is a 1.33GHz Athlon, 256MB. > > I've seen posts here before where keys have been used incorrectly and > hence not providing the benefit. Are the keys in the stylesheet below > being used in a useful manner? > > -------------------------------------- > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> > <!-- XSLT to add more information to database export data [STEP 1] --> > <xsl:variable name="datastructure" select="document('datastructureSmallProjectSchema.xml')"/> > <xsl:key name="fieldlookup" match="//node()[contains(name(), 'field')]/lookup/value" use="concat(ancestor::file/@name, '.', ../../@name, '|', @text)"/> > <xsl:key name="field" match="//node()[contains(name(), 'field') and @length]" use="concat(ancestor::file/@name, '.', @name)"/> > <xsl:template match="*"> > <xsl:copy> > <xsl:copy-of select="attribute::*"/> > <xsl:apply-templates/> > </xsl:copy> > </xsl:template> > <!-- Match each field --> > <xsl:template match="node()[contains(name(), 'field')]"> > <xsl:variable name="currentlocation" select="."/> > <xsl:variable name="name" select="@name"/> > <xsl:variable name="value" select="@textvalue"/> > <xsl:for-each select="$datastructure"> > <xsl:variable name="length"><xsl:value-of select="key('field', $name)/@length"/></xsl:variable> > <xsl:variable name="type"><xsl:choose> > <xsl:when test="key('field', $name)[name() = 'datefield']">date</xsl:when> > <xsl:when test="key('field', $name)[name() = 'timefield']">time</xsl:when> > <xsl:otherwise><xsl:value-of select="key('field', $name)/@type"/></xsl:otherwise> > </xsl:choose></xsl:variable> > <field> > <xsl:copy-of select="$currentlocation/attribute::*[name() != 'value']"/> > <xsl:attribute name="type"><xsl:value-of select="$type"/></xsl:attribute> > <xsl:if test="$length"><xsl:attribute name="length"><xsl:value-of select="$length"/></xsl:attribute></xsl:if> > <xsl:attribute name="textvalue"><xsl:value-of select="$value"/></xsl:attribute> > <xsl:variable name="rawvalue"><xsl:choose> > <xsl:when test="key('field', $name)/lookup and $value != ''"><xsl:call-template name="getrawvalue"> > <xsl:with-param name="name" select="$name"/> > <xsl:with-param name="value" select="$value"/> > </xsl:call-template></xsl:when> > <xsl:otherwise><xsl:value-of select="$value"/></xsl:otherwise> > </xsl:choose></xsl:variable> > <xsl:attribute name="rawvalue"><xsl:value-of select="$rawvalue"/></xsl:attribute> > <xsl:attribute name="paddedvalue"><xsl:call-template name="padvalue"> > <xsl:with-param name="value" select="$rawvalue"/> > <xsl:with-param name="length" select="$length"/> > <xsl:with-param name="type" select="$type"/> > </xsl:call-template></xsl:attribute> > <xsl:apply-templates select="$currentlocation/*"/> > </field> > </xsl:for-each> > </xsl:template> > <xsl:template name="padvalue"> > <xsl:param name="value"/> > <xsl:param name="length"/> > <xsl:param name="type"/> > <xsl:choose> > <!-- Do special conversions for date fields. Assume date are always received as dd/mm/yyyy --> > <xsl:when test="$type = 'date'"><xsl:choose> > <xsl:when test="$length = string-length('dd/mm/yyyy')"><xsl:value-of select="$value"/></xsl:when> > <xsl:when test="$length = string-length('ddmmyy')"><xsl:value-of select="concat(substring($value, 1, 2), substring($value, 4, 2), substring($value, 9, 2))"/></xsl:when> > <xsl:otherwise>Error: Incorrect date format</xsl:otherwise> > </xsl:choose></xsl:when> > <xsl:when test="$length = ''"><xsl:value-of select="$value"/></xsl:when> > <xsl:when test="string-length($value) < $length"> > <xsl:call-template name="padvalue"> > <xsl:with-param name="value"><xsl:value-of select="$value"/><xsl:text> > </xsl:text></xsl:with-param> > <xsl:with-param name="length" select="$length"/> > <xsl:with-param name="type" select="$type"/> > </xsl:call-template> > </xsl:when> > <xsl:when test="string-length($value) = $length"> > <xsl:value-of select="$value"/> > </xsl:when> > <xsl:otherwise>Error: too long</xsl:otherwise> > </xsl:choose> > </xsl:template> > <xsl:template name="getrawvalue"> > <xsl:param name="name"/> > <xsl:param name="value"/> > <xsl:for-each select="$datastructure"> > <xsl:variable name="rawvalue" select="key('fieldlookup', concat($name, '|', $value))/@raw"/> > <xsl:choose> > <xsl:when test="$rawvalue"><xsl:value-of select="$rawvalue"/></xsl:when> > <xsl:otherwise>Error: invalid lookup</xsl:otherwise> > </xsl:choose> > </xsl:for-each> > </xsl:template> > </xsl:stylesheet> > ----------------- > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re[2]: [xsl] correct use of keys?, Kevin Burges | Thread | RE: Re[2]: [xsl] correct use of key, WATKIN-JONES,ADAM (H |
RE: [xsl] How to pass the system da, Michael Kay | Date | MSXML3 -> WAS: [xsl] XML Processor, Joshua Miller |
Month |