473,395 Members | 1,969 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,395 software developers and data experts.

Reading Code/Description lookup via inline XSLT

23
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 3955
jkmyoung
2,057 Expert 2GB
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
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 Expert 2GB
??
Could you post your desired html?
Jan 8 '09 #4
ianoble
23
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
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 Expert 2GB
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
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 Expert 2GB
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
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
ianoble
23
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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
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
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...
0
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...

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.