473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

XSLT Lookup Tables Help.

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">asset #132</id> becomes
<field Name="instrument_id" IsUnique="Y">asset #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:

<pluginRequest>
<senderRef>store</senderRef>
<full>
<asset type="bondFuture">
<id type="master">asset #132</id>
<Category>Bond Future</Category>
<HiPort>DG Z4</HiPort>
<Bloomberg>G Z4 Index</Bloomberg>
<Expiry>29-Dec-04</Expiry>
</asset>
</full>
</pluginRequest>

My desired output:

<LzMessage RequestReference="1">
<LzCreateInstrumentRequest>
<field name="instrument_id" IsUnique="Y">asset #132</field>
<field name="name" IsUnique="N">Bond Future</field>
...etc
<field name="expiration_date" IsUnique="N">29-Dec-04</field>
</LzCreateInstrumentRequest>
</LzMessage>

My actual result:

<LzMessage RequestReference="1"
xmlns:ren="http://www.ora.com/namespaces/rename">
<LzCreateInstrumentRequest>
<field name="id" IsUnique="Y">asset #132</field>
<field name="Category" IsUnique="N">Bond Future</field>
<field name="Expiry" IsUnique="N">29-Dec-04</field>
...etc
</LzCreateInstrumentRequest>
</LzMessage>
My XSLT doc is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 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="yes"/>

<xsl:variable name="lookup" select="document('')/*[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:attribute name="RequestReference">
<xsl:value-of select="1"/>
</xsl:attribute>
<xsl:apply-templates/>
</LzMessage>
</xsl:template>

<xsl:template match="senderRef">
<xsl:apply-templates select="full"/>
</xsl:template>

<xsl:template match="full">
<LzCreateInstrumentRequest>
<xsl:apply-templates select="asset"/>
</LzCreateInstrumentRequest>
</xsl:template>

<!-- Asset -->
<xsl:template match="asset">
<xsl:for-each select="*">
<field>
<xsl:choose>
<xsl:when test="$lookup/ren:element[@from=name(current())]">
<xsl:attribute name="name">
<xsl:value-of select="$lookup/ren:element[@from=name(current())]/@to"/>
</xsl:attribute>
</xsl:when>

<xsl:otherwise>
<xsl:attribute name="name">
<xsl:value-of select="local-name(.)"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>

<xsl:choose>
<xsl:when test="local-name(.) = 'id'">
<xsl:attribute name="IsUnique"><xsl:text>Y</xsl:text></xsl:attribute>
</xsl:when>

<xsl:otherwise>
<xsl:attribute 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
Jul 20 '05 #1
4 4264
> My desired output:

<LzMessage RequestReference="1">
<LzCreateInstrumentRequest>
<field name="instrument_id" IsUnique="Y">asset #132</field>
<field name="name" IsUnique="N">Bond Future</field>
...etc
<field name="expiration_date" IsUnique="N">29-Dec-04</field>
</LzCreateInstrumentRequest>
</LzMessage>

My actual result:

<LzMessage RequestReference="1"
xmlns:ren="http://www.ora.com/namespaces/rename">
<LzCreateInstrumentRequest>
<field name="id" IsUnique="Y">asset #132</field>
<field name="Category" IsUnique="N">Bond Future</field>
<field name="Expiry" IsUnique="N">29-Dec-04</field>
...etc
</LzCreateInstrumentRequest>
</LzMessage>


Hi,

Your XSLT gives the 'desired' output with me (using Saxon).
Maybe your processor cannot handle tree fragments in variables.
You could try using:
<xsl:when test="document('')//ren:element[@from=name(current())]"/>
and omit the use of $lookup ?

By the way, I really like your idea of the lookup table for attribute
renaming.

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2
In article <op**************@news.pandora.be>,
Joris Gillis <ro**@pandora.be> wrote:
Your XSLT gives the 'desired' output with me (using Saxon).
And with all the processors I have to hand. Which one does it not
work with?
Maybe your processor cannot handle tree fragments in variables.


There isn't actually a result-tree fragment there: it's opening the
stylesheet itself with document('') and the value of the variable is
just a node set from that document.

The most likely thing seems to be that your processor doesn't handle
document('') properly. You could try putting the table in a different
file.

-- Richard
Jul 20 '05 #3

Thanks for taking the time to look at my problem.
I'm currently developing in C# on windows XP with MSXML4.
I call my transformation something like this:

xslt.Transform(xpathDocument, null, xmlMemoryStream, null);

I did try using
document('')//ren:element[@from=name(current())]
instead of the $lookup variable, but no change in output. I have a nasty
feeling that MSXML4 doesn't support the document() function call, I know
ealier versions didn't.

I don't have access to any other parsers unfortunately.

Any alternative approach suggestions as to using lookup tables would be
great as the lookup table is exactly what I require else I will have to
write serveral hundred templates, which is not idealic.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4

Thanks for taking the time to look at my problem.
I'm currently developing in C# on windows XP with MSXML4.
I call my transformation something like this:

xslt.Transform(xpathDocument, null, xmlMemoryStream, null);

I did try using
document('')//ren:element[@from=name(current())]
instead of the $lookup variable, but no change in output. I have a nasty
feeling that MSXML4 doesn't support the document() function call, I know
ealier versions didn't.

I don't have access to any other parsers unfortunately.

Any alternative approach suggestions as to using lookup tables would be
great as the lookup table is exactly what I require else I will have to
write serveral hundred templates, which is not idealic.

Adrian Charteris
BA/Developer
Insight Investments
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ola Natvig | last post by:
Anybody out there who knows if the 4suite implementation of XSLT are a threadsafe one? -- -------------------------------------- Ola Natvig <ola.natvig@infosense.no> infoSense AS / development
1
by: øystein | last post by:
Hi! I got an xml file that goes like this. <question id=10 correct_answer=2> <alternative>Answer 1</alternative> <alternative>Answer 2</alternative> <alternative>Answer 3</alternative>...
3
by: Mike Whittemore | last post by:
I am trying to convert an HTML table into a list of name-value pairs, one pair per field in the table. I believe my XSLT is correct, but I've tried both Xalan and Saxon, which both fail with...
4
by: Chris Kettenbach | last post by:
Hi Peter, I get error when processing the stylesheet. It errors here. <xsl:for-each select="registration)=1]"> specifically: Expression does not return a DOM node. registration)=1]<--
3
by: my-wings | last post by:
I've been reading about how evil Lookup fields in tables are, but I've got to be missing something really basic. I know this subject has been covered before, because I've just spent an hour or two...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
3
by: super.raddish | last post by:
Greetings, I am relatively new to, what I would call, advanced XSLT/XPath and I am after some advice from those in the know. I am attempting to figure out a mechanism within XSLT to compare the...
11
by: ianoble | last post by:
I've been trying to piece together various code snippets to create a lookup table inside my xslt without the need for a supplemental xml file. Here is what I have so far. As of now, it does not...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.