Hi I'm currently trying to use a lookup table for converting one xml
doc to another using a XSLT transformation. Ideally I would like my
first xml doc to be converted to my second xml doc below.
All that I want is to replace node names with a matching value in the
lookup table and place the result into an field attribute pair:
Example: id to be renamed instrument_id thus
<id type="master">a sset #132</id> becomes
<field Name="instrumen t_id" IsUnique="Y">as set #132</field>
My problem is that none of the name matches are being output in the
resulting xml document.
My first XML has an asset request:
<pluginReques t>
<senderRef>stor e</senderRef>
<full>
<asset type="bondFutur e">
<id type="master">a sset #132</id>
<Category>Bon d Future</Category>
<HiPort>DG Z4</HiPort>
<Bloomberg>G Z4 Index</Bloomberg>
<Expiry>29-Dec-04</Expiry>
</asset>
</full>
</pluginRequest>
My desired output:
<LzMessage RequestReferenc e="1">
<LzCreateInstru mentRequest>
<field name="instrumen t_id" IsUnique="Y">as set #132</field>
<field name="name" IsUnique="N">Bo nd Future</field>
...etc
<field name="expiratio n_date" IsUnique="N">29-Dec-04</field>
</LzCreateInstrum entRequest>
</LzMessage>
My actual result:
<LzMessage RequestReferenc e="1"
xmlns:ren="http ://www.ora.com/namespaces/rename">
<LzCreateInstru mentRequest>
<field name="id" IsUnique="Y">as set #132</field>
<field name="Category" IsUnique="N">Bo nd Future</field>
<field name="Expiry" IsUnique="N">29-Dec-04</field>
...etc
</LzCreateInstrum entRequest>
</LzMessage>
My XSLT doc is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:ren="http ://www.ora.com/namespaces/rename">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
omit-xml-declaration="ye s"/>
<xsl:variable name="lookup" select="documen t('')/*[ren:*]"/>
<ren:element from="id" to="instrument_ id"/>
<ren:element from="Category" to="name"/>
<ren:element from="Expiry" to="expiration_ date"/>
<xsl:template match="/">
<LzMessage>
<xsl:attribut e name="RequestRe ference">
<xsl:value-of select="1"/>
</xsl:attribute>
<xsl:apply-templates/>
</LzMessage>
</xsl:template>
<xsl:template match="senderRe f">
<xsl:apply-templates select="full"/>
</xsl:template>
<xsl:template match="full">
<LzCreateInstru mentRequest>
<xsl:apply-templates select="asset"/>
</LzCreateInstrum entRequest>
</xsl:template>
<!-- Asset -->
<xsl:template match="asset">
<xsl:for-each select="*">
<field>
<xsl:choose>
<xsl:when test="$lookup/ren:element[@from=name(curr ent())]">
<xsl:attribut e name="name">
<xsl:value-of select="$lookup/ren:element[@from=name(curr ent())]/@to"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwis e>
<xsl:attribut e name="name">
<xsl:value-of select="local-name(.)"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="local-name(.) = 'id'">
<xsl:attribut e name="IsUnique" ><xsl:text>Y</xsl:text></xsl:attribute>
</xsl:when>
<xsl:otherwis e>
<xsl:attribut e name="IsUnique" ><xsl:text>N</xsl:text></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="."/>
</field>
</xsl:for-each>
</xsl:template>
<!--End Asset-->
</xsl:stylesheet>
Please help! What am I doing wrong?
Adrian