473,756 Members | 8,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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">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
Jul 20 '05 #1
4 4304
> 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>


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(curr ent())]"/>
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.b e> 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(curr ent())]
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(curr ent())]
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
1917
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
1871
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> <alternative>Answer 4</alternative> </question>
3
1653
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 different results. Below I've listed my HTML input, my expected XML output, my XSLT, and the actual output from both Saxon and Xalan. Thanks in advance. HTML Input ---------- <html>
4
1832
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
2920
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 reading about it on google, but there is something I still don't understand, and I'm hoping someone will be willing to explain it to me in small words. Let's say I have a table for addresses, and it includes a field for state. What I would...
3
10663
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 that are hard to find. The main problem I am having right now is that I have a report that is sorted by one of these lookup fields and it only displays the record's ID number. When I add the source table to the query it makes several records...
18
2084
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 look up what each feature depends on and gerenate a text file. For example, in the following file, I would like to find out feature A depends on A1 and A2 and feature B depends on B1 and B2. And write that to a text file.
3
9612
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 difference between two source documents and output node-sets which are "different" (changed or new) to new XML files using xsl:result-document To describe the problem I have provided some example data below along with my a portion of my current...
11
4000
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 return anything in the output. I would love to be able to query the xref:factor table to retrieve the value of xref:factor/lookup <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE xsl:stylesheet > <xsl:stylesheet...
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10040
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9873
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.