|
next
|
 Subject: Efficient merge and split Author: James Durning Date: 19 Oct 2004 12:59 PM
|
First of all, I know about xsl:document(), (XSLT 1.1) and xsl:result-document(href='') (XSLT 2.0) and xt:document etc...
I've got 2 documents which I am merging and then splitting off into multiple documents. Here's an abstraction of the code:
Source file:
<library>
<book key="1" author="Dickens" other="F"/>
<book key="2" author="Verne" other="T">
</library>
Lookup table:
<lookup>
<row key="1" globalid="562"/>
<row key="49" globalid="143"/>
<row key="2" globalid="322"/>
</lookup>
---
Desired Output 1
<output1>
<book globalid="562" author="Dickens">
<book globalid="322" author="Verne">
</output1>
Output2
<output2>
<book globalid="562" other="F">
<book globalid="322" other="T">
</output2>
---
I can get either of these files seperately by using seperate xslt files, but what I want is something that minimizes the lookup. Eg, what I have now:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:variable name="LOOKUP" select=document("'C:/xslt/lookuptable.xml'")/lookup/>
<xsl:template match="/library">
<output1>
<xsl:for-each select="book">
<book>
<xsl:variable name="KEY" select="@key"/>
<xsl:variable name="ID" select="$LOOKUP/row[$KEY=@key]/globalid"/><!-- LOOKUP HERE -->
<xsl:attribute name="globalid"><xsl:value-of select="$ID"/></xsl:attribute>
<xsl:attribute name="author"><xsl:value-of select="@author"/></xsl:attribute>
</book>
</xsl:for-each>
</output1>
</xsl:template>
</xsl:output>
</xsl:stylesheet>
Output2 is the same except I change 'output1' elements to 'output2', and 'author' with 'other' everywhere.
I would like someway to minimize the lookup, eg do it once per book. Is there any way to do this without creating a secondary xml document? I want to use xsl:document (with SAXON) if possible.
What I tried: inside for loop, using <xsl:document href="output2">global id = id, other = @other, ...etc.
but then the xsl:document clears the document each time, so I wind up with one element.
I know this is a hard question. Thank you to anyone who has any ideas not yet mentioned.
|
|
|