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 [<!ENTITY nbsp "*">]>
-
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version="1.0"
-
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
-
xmlns:xref="http://www.dummy.com/xref"
-
extension-element-prefixes="xref">
-
-
<xsl:output method="html" version="3.0" encoding="iso-8859-1" indent="yes"/>
-
-
<xref:factor>
-
<lookup factorcode="K">Test 1</lookup>
-
<lookup factorcode="I">Test 2</lookup>
-
<lookup factorcode="B">Test 3</lookup>
-
<lookup factorcode="G">Test 4</lookup>
-
</xref:factor>
-
-
<xsl:key name="factor" match="xref:factor/lookup" use="@factorcode" />
-
<xsl:variable name="factors" select='document("")//xref:factor' />
-
-
<xsl:template match="/CREDITDATA">
-
<html>
-
<head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head>
-
<body>
-
<xsl:for-each select="scoreinformation">
-
<xsl:variable name="origfactor" select="normalize-space(factor1)"/>
-
<xsl:for-each select='$factors'>
-
<xsl:value-of select='key("factor", $origfactor)'/>
-
</xsl:for-each>
-
</xsl:for-each>
-
</body>
-
</html>
-
</xsl:template>
-
</xsl:stylesheet>
-
Here is a sample of the xml file: -
<CREDITDATA>
-
<scoreinformation ID="1">
-
<score>0519</score>
-
<factor1>K</factor1>
-
<factor2>I</factor2>
-
<factor3>B</factor3>
-
<factor4>G</factor4>
-
<model>B</model>
-
</scoreinformation>
-
</CREDITDATA>
-
11 3961 jkmyoung 2,057
Recognized Expert Top Contributor
The key element only works on your target document, not the xslt. -
<xsl:for-each select="scoreinformation">
-
<xsl:value-of select="$factors//lookup[@factorcode = current()/factor1]"/>
-
</xsl:for-each>
-
Here is the updated code, but it's still not outputing anything other than the static HTML. -
<?xml version="1.0" encoding="iso-8859-1"?>
-
<!DOCTYPE xsl:stylesheet [<!ENTITY nbsp "*">]>
-
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version="1.0"
-
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
-
xmlns:xref="http://www.dummy.com/xref"
-
extension-element-prefixes="xref">
-
-
<xsl:output method="html" version="3.0" encoding="iso-8859-1" indent="yes"/>
-
-
<xref:factor>
-
<lookup factorcode="K">Test 1</lookup>
-
<lookup factorcode="I">Test 2</lookup>
-
<lookup factorcode="B">Test 3</lookup>
-
<lookup factorcode="G">Test 4</lookup>
-
</xref:factor>
-
-
<xsl:key name="factor" match="xref:factor/lookup" use="@factorcode" />
-
<xsl:variable name="factors" select='document("")//xref:factor' />
-
-
<xsl:template match="/CREDITDATA">
-
<html>
-
<head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head>
-
<body>
-
<xsl:for-each select="scoreinformation">
-
<xsl:value-of select="$factors//lookup[@factorcode = 'K']"/> <!--current()/factor1]"/>//-->
-
<!--
-
<xsl:variable name="origfactor" select="normalize-space(factor1)"/>
-
<xsl:for-each select='$factors'>
-
<xsl:value-of select='key("factor", $origfactor)'/>
-
</xsl:for-each>
-
//-->
-
</xsl:for-each>
-
</body>
-
</html>
-
</xsl:template>
-
</xsl:stylesheet>
-
jkmyoung 2,057
Recognized Expert Top Contributor
??
Could you post your desired html?
I supposed it should look like this: -
<html xmlns:msxsl="urn:schemas-microsoft-com:xslt">
-
<head><META http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>
-
<body>
-
Test 1
-
</body>
-
</html>
-
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.
jkmyoung 2,057
Recognized Expert Top Contributor
I stand by my earlier post: -
<?xml version="1.0" encoding="iso-8859-1"?>
-
<!DOCTYPE xsl:stylesheet [<!ENTITY nbsp "*">]>
-
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version="1.0"
-
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
-
xmlns:xref="http://www.dummy.com/xref"
-
extension-element-prefixes="xref">
-
-
<xsl:output method="html" version="3.0" encoding="iso-8859-1" indent="yes"/>
-
-
<xref:factor>
-
<lookup factorcode="K">Test 1</lookup>
-
<lookup factorcode="I">Test 2</lookup>
-
<lookup factorcode="B">Test 3</lookup>
-
<lookup factorcode="G">Test 4</lookup>
-
</xref:factor>
-
-
<xsl:key name="factor" match="xref:factor/lookup" use="@factorcode" />
-
<xsl:variable name="factors" select='document("")//xref:factor' />
-
-
<xsl:template match="/CREDITDATA">
-
<html>
-
<head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head>
-
<body>
-
<xsl:for-each select="scoreinformation">
-
<xsl:value-of select="$factors//lookup[@factorcode = current()/factor1]"/>
-
</xsl:for-each>
-
</body>
-
</html>
-
</xsl:template>
-
</xsl:stylesheet>
-
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!
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.
Sure! -
// Get the generated xml
-
XPathDocument xDoc = new XPathDocument(GetXML());
-
-
// Load the stylesheet and perform the transform.
-
XslTransform xslt = new XslTransform();
-
xslt.Load(@"c:\Temp\CreditReport.xslt");
-
XmlTextWriter myWriter = new XmlTextWriter(@"c:\Temp\test.html", null) ;
-
xslt.Transform(xDoc, null, myWriter, null);
-
jkmyoung 2,057
Recognized Expert Top Contributor
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!
Sign in to post your reply or Sign up for a free account.
Similar topics |
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,:
...
|
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.
...
|
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>...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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: 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,...
|
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...
|
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...
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |