473,499 Members | 1,808 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 3961
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
jkmyoung
2,057 Recognized Expert Top Contributor
I think you use an XmlResolver: specificially XmlUrlResolver
XslTransform.Transform Method (IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver) (System.Xml.Xsl)
XmlUrlResolver Class (System.Xml)
Jan 12 '09 #11
ianoble
23 New Member
Shoot, that was so simple! I'm still on .net 1.1, so I didn't think to look at the XmlUrlResolver class, but that did the trick.

Thank you again for your help!
Jan 12 '09 #12

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

Similar topics

2
2760
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,: ...
4
4276
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. ...
1
1210
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>...
4
3493
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...
3
2410
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...
40
2754
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...
4
1387
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...
18
2043
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...
11
6083
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...
0
7007
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...
0
7174
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,...
0
7220
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...
1
6894
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...
0
5470
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,...
0
4600
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...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
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 ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.