473,769 Members | 4,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading Code/Description lookup via inline XSLT

23 New Member
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

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE xsl:stylesheet [<!ENTITY nbsp "*">]> 
  3. <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version="1.0"
  4.     xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
  5.     xmlns:xref="http://www.dummy.com/xref"
  6.     extension-element-prefixes="xref">
  7.  
  8.     <xsl:output method="html" version="3.0" encoding="iso-8859-1" indent="yes"/>
  9.  
  10.     <xref:factor>
  11.         <lookup factorcode="K">Test 1</lookup>
  12.         <lookup factorcode="I">Test 2</lookup>
  13.         <lookup factorcode="B">Test 3</lookup>
  14.         <lookup factorcode="G">Test 4</lookup>
  15.     </xref:factor>
  16.  
  17.     <xsl:key name="factor" match="xref:factor/lookup" use="@factorcode" />
  18.     <xsl:variable name="factors" select='document("")//xref:factor' />
  19.  
  20.     <xsl:template match="/CREDITDATA">
  21.         <html>
  22.             <head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head>
  23.             <body>
  24.                 <xsl:for-each select="scoreinformation">
  25.                     <xsl:variable name="origfactor" select="normalize-space(factor1)"/>
  26.                     <xsl:for-each select='$factors'>
  27.                         <xsl:value-of select='key("factor", $origfactor)'/>
  28.                     </xsl:for-each>
  29.                 </xsl:for-each>
  30.             </body>
  31.         </html>
  32.     </xsl:template>
  33. </xsl:stylesheet>
  34.  
Here is a sample of the xml file:

Expand|Select|Wrap|Line Numbers
  1. <CREDITDATA>
  2.     <scoreinformation ID="1">
  3.         <score>0519</score> 
  4.         <factor1>K</factor1> 
  5.         <factor2>I</factor2> 
  6.         <factor3>B</factor3> 
  7.         <factor4>G</factor4> 
  8.         <model>B</model> 
  9.     </scoreinformation>
  10. </CREDITDATA>
  11.  
Jan 7 '09 #1
11 4002
jkmyoung
2,057 Recognized Expert Top Contributor
The key element only works on your target document, not the xslt.


Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="scoreinformation"> 
  2.   <xsl:value-of select="$factors//lookup[@factorcode = current()/factor1]"/>
  3. </xsl:for-each>
  4.  
Jan 8 '09 #2
ianoble
23 New Member
Here is the updated code, but it's still not outputing anything other than the static HTML.

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE xsl:stylesheet [<!ENTITY nbsp "*">]> 
  3. <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version="1.0"
  4.     xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
  5.     xmlns:xref="http://www.dummy.com/xref"
  6.     extension-element-prefixes="xref">
  7.  
  8.     <xsl:output method="html" version="3.0" encoding="iso-8859-1" indent="yes"/>
  9.  
  10.     <xref:factor>
  11.         <lookup factorcode="K">Test 1</lookup>
  12.         <lookup factorcode="I">Test 2</lookup>
  13.         <lookup factorcode="B">Test 3</lookup>
  14.         <lookup factorcode="G">Test 4</lookup>
  15.     </xref:factor>
  16.  
  17.     <xsl:key name="factor" match="xref:factor/lookup" use="@factorcode" />
  18.     <xsl:variable name="factors" select='document("")//xref:factor' />
  19.  
  20.     <xsl:template match="/CREDITDATA">
  21.         <html>
  22.             <head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head>
  23.             <body>
  24.                 <xsl:for-each select="scoreinformation">
  25.                     <xsl:value-of select="$factors//lookup[@factorcode = 'K']"/> <!--current()/factor1]"/>//-->
  26.                     <!--
  27.                     <xsl:variable name="origfactor" select="normalize-space(factor1)"/>
  28.                     <xsl:for-each select='$factors'>
  29.                         <xsl:value-of select='key("factor", $origfactor)'/>
  30.                     </xsl:for-each>
  31.                     //-->
  32.                 </xsl:for-each>
  33.             </body>
  34.         </html>
  35.     </xsl:template>
  36. </xsl:stylesheet>
  37.  
Jan 8 '09 #3
jkmyoung
2,057 Recognized Expert Top Contributor
??
Could you post your desired html?
Jan 8 '09 #4
ianoble
23 New Member
I supposed it should look like this:

Expand|Select|Wrap|Line Numbers
  1. <html xmlns:msxsl="urn:schemas-microsoft-com:xslt">
  2.     <head><META http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>
  3.     <body>
  4.         Test 1
  5.     </body>
  6. </html>
  7.  
Jan 8 '09 #5
ianoble
23 New Member
I found that if I set the xml-stylesheet of the xml file, the lookup table works correctly. However, if I use XslTransform in c#, the lookup table does not work. I'm not sure what the difference is, but for now I'll just have to specify the xml-stylesheet for my xml file.
Jan 9 '09 #6
jkmyoung
2,057 Recognized Expert Top Contributor
I stand by my earlier post:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>  
  2. <!DOCTYPE xsl:stylesheet [<!ENTITY nbsp "*">]>   
  3. <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version="1.0"  
  4.     xmlns:msxsl="urn:schemas-microsoft-com:xslt"   
  5.     xmlns:xref="http://www.dummy.com/xref"  
  6.     extension-element-prefixes="xref">  
  7.  
  8.     <xsl:output method="html" version="3.0" encoding="iso-8859-1" indent="yes"/>  
  9.  
  10.     <xref:factor>  
  11.         <lookup factorcode="K">Test 1</lookup>  
  12.         <lookup factorcode="I">Test 2</lookup>  
  13.         <lookup factorcode="B">Test 3</lookup>  
  14.         <lookup factorcode="G">Test 4</lookup>  
  15.     </xref:factor>  
  16.  
  17.     <xsl:key name="factor" match="xref:factor/lookup" use="@factorcode" />  
  18.     <xsl:variable name="factors" select='document("")//xref:factor' />  
  19.  
  20.     <xsl:template match="/CREDITDATA">  
  21.         <html>  
  22.             <head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head>  
  23.             <body>  
  24. <xsl:for-each select="scoreinformation">   
  25.   <xsl:value-of select="$factors//lookup[@factorcode = current()/factor1]"/> 
  26. </xsl:for-each>  
  27.             </body>  
  28.         </html>  
  29.     </xsl:template>  
  30. </xsl:stylesheet>  
  31.  
Jan 9 '09 #7
ianoble
23 New Member
Definitely. That works great if I declare the stylesheet in the xml file. Unfortunately I am generating the xml dynamically and I can't set the stylesheet like that. So this seems to be a c# problem, rather than an xslt.

Thank you for your help!
Jan 12 '09 #8
jkmyoung
2,057 Recognized Expert Top Contributor
Could you post your C# code? There may be a setting where the document() function is enabled/disabled depending on a particular property.
Jan 12 '09 #9
ianoble
23 New Member
Sure!

Expand|Select|Wrap|Line Numbers
  1. // Get the generated xml
  2. XPathDocument xDoc = new XPathDocument(GetXML());
  3.  
  4. // Load the stylesheet and perform the transform.
  5. XslTransform xslt = new XslTransform();
  6. xslt.Load(@"c:\Temp\CreditReport.xslt");
  7. XmlTextWriter myWriter = new XmlTextWriter(@"c:\Temp\test.html", null) ;
  8. xslt.Transform(xDoc, null, myWriter, null);
  9.  
Jan 12 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2775
by: Xtr | last post by:
Hello, Is it possible, using xsl, to indent most tags, but preserve the position of tags that are inline (surrounded by text)? For example, given the following,: <text><p>text<b>text</b></p></text> <text><p>text<b>text</b></p></text>
4
4305
by: Adrian Charteris | last post by:
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...
1
1223
by: amessimon | last post by:
Hi I need to read from an XML document formatted in this manner <?xml version="1.0"?> <result> <book> <title>A new book</title> <url>http://www.newbookstore.co.uk</url> <description>perspiciatis unde omnis iste natus error sit voluptatem
4
3516
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I click a button on a pop-up window the javascript for that button click does a 'button.form.submit'. On the Server side there is a Button click event for this button, but for some reason it no longer fires. It worked fine before and everything...
3
2429
by: jbsfe | last post by:
I have "Spilt" my database and the "lookup" and "seek" methods that previously worked, no longer do. I have learnd from reviewing the posts that the "lookup" and "Seek" methods cannot be used on linked tables and that you cannot set an "index" for a linked table. What I don't know how to do, is revise my code to complete the same tasks as it it did before I split the database. I'm sure the problem lies is this block of code: 'Define...
40
2804
by: GTi | last post by:
Is there any source code documentation tools available for Visual Studio 2005 ? I have created a LIB that must be documented. Must I do it by hand or is it some kind of tools to pre document my source code?
4
1409
by: J.D. | last post by:
Hello, I am working on a client project and they have a connection to a catalog system that passes data back and forth as xml over http The format of the data is as follow(s) > <?xml version="1.0"?> > > <customer-redemption>
18
2086
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.
11
6109
by: J_Zanetti | last post by:
Hello everybody, In my applications I've a ton of scripts that use remote XML file to fill forms and evaluate contents; In these scripts I always use the method SelectNode (that, with some workaround, works fine also in Mozilla). I've just found out that this method doesnt work in Safari browser, therefore my applications are not usable by this browser. Can anyone provide me any solution or workaround to be able to read XML files in...
0
10211
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...
1
9994
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,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7409
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
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
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
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.