Hi,
You can use the document() function in XSLT to bring in additional input XML
documents into the transformation.
For example, say your primary input XML (the accounts) looked like...
== accounts.xml =================================
<?xml version="1.0"?>
<accounts>
<acc id="1">
<balance>100</balance>
<currency>USD</currency>
</acc>
<acc id="2">
<balance>200</balance>
<currency>EUR</currency>
</acc>
</accounts>
== end of accounts.xml ==========================
and your secondary input XML document resided in the same directory as
"accounts.xml" and looked like...
== currencies.xml ===============================
<?xml version="1.0"?>
<currencies>
<currency id="1">
<code>USD</code>
</currency>
<currency id="2">
<code>EUR</code>
</currency>
</currencies>
== end of currencies.xml ========================
then your XSLT might look something like...
== XSLT ===============================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="currency-lookups"
select="document('currencies.xml',/)/currencies/currency"/>
<xsl:template match="accounts">
<output>
<xsl:apply-templates select="acc"/>
<xsl:copy-of select="$currency-lookups"/>
</output>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@* | text() | comment() | processing-instruction()">
<xsl:copy/>
</xsl:template>
<xsl:template match="acc/currency">
<currency-id>
<xsl:value-of select="$currency-lookups[code = current()]/@id"/>
</currency-id>
</xsl:template>
</xsl:stylesheet>
== end XSLT ========================
HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
"Maciej Wegorkiewicz" <we******@interia.pl> wrote in message
news:cm**********@domitilla.aioe.org...
Hi,
I have small experience in XSLT processing and I have a problem which I
cannot solve. Can you look at it?
I have an input file containing info about bank accounts like this:
(...)
<acc id="1">
<balance>100</balance>
<currency>USD</currency>
</acc>
<acc id="2">
<balance>200</balance>
<currency>EUR</currency>
</acc>
(.... and so on ....)
now, additionaly i have a file with currency definitions:
(...)
<currency id="1">
<code>USD</code>
</currency>
<currency id="2">
<code>EUR</code>
</currency>
(...)
what I need is to get such a result:
(...)
<acc id="1">
<balance>100</balance>
<currency-id>1</currency-id>
</acc>
<acc id="2">
<balance>200</balance>
<currency-id>2</currency-id>
</acc>
<currency id="1">
<code>USD</code>
</currency>
<currency id="2">
<code>EUR</code>
</currency>
(...)
I need to get it by some XSLT program which has the first file (with
accounts) as input and must produce the last file. It can contain the
file with currency definitions (as this file is constant).
I imagine I need some kind of program where XSLT creates a map type
array from currency definitions and when processing accounts it replaces
currency codes with their respective ids.
I must add that I have many currencies (above 100 or sth) so it would be
easier no to define map array by hand, but I can do it if it is necessary.
Can you give me any hint or an address of any similar XSLT example?
Thanks.
Maciek