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>
-----------------
--
May the flares be with you,
Kevin mailto:xmldude@xxxxxxxxxxxxxxxx
++++++++++++ Cool music - http://burieddreams.com/marshan
++++++ Attitude Webzine - http://burieddreams.com/attitude
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|